I'm using this to get keyword arguments for my shell script
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
-u)
USERID="$2"
shift # past argument
shift # past value
;;
-n)
JOBNAME="$2"
shift # past argument
shift # past value
;;
-j)
job="$2"
shift # past argument
shift # past value
;;
*) echo "Improper usage"; exit 1;;
esac
done
Now the job
variable usually is multi-word. I can give the whole value for that argument inside a quote and it works perfectly. But is it possible to provide the value without any quote but still store inside that single variable. For example, this works
./myscript -j "my long string"
and it stores "my long string"
to the variable job
. But I want this to work too similarly,
./myscript -j my long string
./myscript -j "foo bar" file.txt
is clear, but./myscript -j foo bar file.txt
is ambiguous. Or with other options, where does the string end in:./myscript -j foo bar -u user
? You could decide the next arg starting with a dash ends the string and is itself taken as an option, but then you'd be limiting the allowed set of values in the job string.