I have a script count_args
that counts arguments:
#!/bin/sh
echo $#
If I call it with these options, it tells me it gets two arguments:
$ ./count_args --options '1 2'
2
But if I construct the arguments in a script test_args
like so:
#!/bin/sh
ARGS="--options '1 2'"
./count_args ${ARGS}
...I get the result:
$ ./test_args
3
Why is the '1 2'
being split in the script? How can I avoid this in a POSIX compliant way, from the calling script? Is it possible to still store arguments in variables somehow so that I can separate them in more complex scripts (eg. having ARGS_1
and ARGS_2
)?
Note that my /bin/sh
is dash
.