Facebooktwittergoogle_plusredditpinterestlinkedinmail

Shell script to pass multiple arguments with options

#!/bin/bash

if (($# == 0)); then
echo "Please pass argumensts -t <task1><task2>... -d <date>.."
exit 2
fi
while getopts ":t:d:" opt; do
case $opt in
t)
echo "-t was triggered, Parameter: $OPTARG" >&2
TASKS=$OPTARG
;;
d)
echo "-d was triggered, Parameter: $OPTARG" >&2
RDATE=$OPTARG
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
esac
done
echo "Go thru selection"
for TASK in $TASKS;
do
if [ "$TASKS" == "d1" ]
then
echo "Inside the d1"
echo -n "Choose option p-partial, hit enter for all >"
read DType
echo "You have choosen $DType"

fi
echo "Task: $TASK"
done

echo "go thru selection date"

##Check Date
date "+%Y=%m-%d" -d "$RDATE" > /dev/null 2>&1
is_valid=$?
echo $RDATE
echo $is_valid

exit 0
Shell script to pass multiple arguments with options Roopendra LinuxScripting,
Shell script to pass multiple arguments with options #!/bin/bashif (($# == 0)); then echo 'Please pass argumensts -t <task1><task2>... -d <date>..' exit 2 fi while getopts ':t:d:' opt; do case $opt in t) echo '-t was triggered, Parameter: $OPTARG' >&2 TASKS=$OPTARG ;; d) echo '-d was triggered, Parameter: $OPTARG' >&2 RDATE=$OPTARG ;; \?) echo 'Invalid option: -$OPTARG' >&2 exit 1 ;; 🙂 echo 'Option -$OPTARG requires an argument.' >&2 exit...
Shell script to pass multiple arguments with options <pre>#!/bin/bashif (($# == 0)); then echo "Please pass argumensts -t <task1><task2>... -d <date>.." exit 2 fi while getopts ":t:d:" opt; do case $opt in t) echo "-t was triggered, Parameter: $OPTARG" >&2 TASKS=$OPTARG ;; d) echo "-d was triggered, Parameter: $OPTARG" >&2 RDATE=$OPTARG ;; \?) echo "Invalid option: -$OPTARG" >&2 exit 1 ;; 🙂 echo "Option -$OPTARG requires an argument." >&2 exit 1 ;; esac done echo "Go thru selection" for TASK in $TASKS; do if [ "$TASKS" == "d1" ] then echo "Inside the d1" echo -n "Choose option p-partial, hit enter for all >" read DType echo "You have choosen $DType"fi echo "Task: $TASK" doneecho "go thru selection date"##Check Date date "+%Y=%m-%d" -d "$RDATE" > /dev/null 2>&1 is_valid=$? echo $RDATE echo $is_validexit 0</pre>
(Visited 71 times, 20 visits today)
Facebooktwittergoogle_pluslinkedinrss