I have a bash script like this :
usage="setup.sh [-localsource path to dir] [-help]";
for i in $@
do
if [ "$localSourceOpt" = 1 ]
then
localSource=$i
localSourceOpt=0;
fi
if [ "$i" = "-localsource" ]
then
localSourceOpt=1;
fi
if [ "$i" = "-help" ]
then
echo "$usage";
exit;
fi
done
which requires on argument e.g
setup.sh -localsource PATH
what I need is to add another argument which MIGHT have multiple argument values e.g
setup.sh -localsource PATH -locbranches one two three
What I should do to capture values passed for argument “-locbranches”
thanks in advance
I note that you’re having to code a lot of logic to handle the simplest command-line argument mechanism, and I’d perhaps suggest using the
bashgetopts functionality instead.This makes the single argument option work trivial. For multiple arguments it doesn’t work well, and you would have to quote the args e.g.
-option "1 2 3". However it does handle multiple arguments in the following scenario.i.e. the
one two threearen’t linked to any command line option. An alternative is to specify the option for each argument e.g.