I have a bash script which can be passed a number of different arguments and variables to be used by the script itself. Some of the parameters get assigned to variables. The second while loop does not appear to be running when the program tries to execute it. I've simplified the following script for confidentiality/simplicity reasons.
./myscript --dir2 /new/path
while :; do
case $1 in
--var1) $var1=$2
;;
--var2) $var2=$2
;;
"") break
esac
shift
done
$dir1=/default/directory
$dir2=/default/directory
while :; do
case $1 in
--dir1) $dir1=$2
;;
--dir2) $dir2=$2
;;
"") break
esac
shift
done
echo "Expect /default/directory, returned: $dir1"
echo "Expect /new/path, returned: $dir2"
Here's what my program would effectively return.
Expected /default/directory, returned: /default/directory
Expected /new/path, returned: /default/directory
Is there a better way to go about this? Or another way to iterate over the parameters originally passed to the script? Thanks for the help!