Invoking a shell script with command line arguments containing spaces is generally solved by enclosing the argument in quotes:
getParams.sh 'one two' 'foo bar'
Produces:
one two
foo bar
getParams.sh:
while [[ $# > 0 ]]
do
echo $1
shift
done
However, if a shell variable is first defined to hold the value of the arguments such as:
args="'one two' 'foo bar'"
then why does:
getParams.sh $args
not recognize the single quotes enclosing the grouped arguments? The output is:
'one
two'
'three
four'
How can I store command line arguments containing spaces into a variable so that when getParams is invoked, the arguments are grouped according to the quoted arguments just as in the original example?
[[ $# > 0 ]]does a string comparison.[[ $# -gt 0 ]]or(( $# > 0 ))or evenwhile (($#))