I am trying to call a script from another script and the command line arguments are being parsed incorrectly. Is this some bug or am I missing something?
test.sh
#!/bin/bash
set -o errexit
set -o nounset
set -x
while test $# -gt 0; do
case "$1" in
-n) shift
name=$1
shift
;;
-s)
shift
ssh_options=$1
shift
;;
*)
echo "see --help"
exit 1
;;
esac
done
$ssh_cmd="${ssh_options}"
echo "${name} ssh_options=${ssh_options}"
call_test.sh
#!/bin/bash
set -x
cmd=$'./test.sh -n foo -s \"-foo -bar -F\"'
$($cmd)
echo done
#output
./test.sh -n foo -s "-foo -bar -F"
+ test 4 -gt 0
+ case "$1" in
+ shift
+ name=foo
+ shift
+ test 2 -gt 0
+ case "$1" in
+ shift
+ ssh_options='-foo -bar -F'
+ shift
+ test 0 -gt 0
+ echo 'foo ssh_options=-foo -bar -F'
foo ssh_options=-foo -bar -F
./call_test.sh
+ cmd='./test.sh -n foo -s "-foo -bar -F"'
++ ./test.sh -n foo -s '"-foo' -bar '-F"'
+ test 6 -gt 0
+ case "$1" in
+ shift
+ name=foo
+ shift
+ test 4 -gt 0
+ case "$1" in
+ shift
+ ssh_options='"-foo'
+ shift
+ test 2 -gt 0
+ case "$1" in
+ echo 'see --help'
+ exit 1
+ see --help
./call_test.sh: line 5: see: command not found
+ echo done
done
Any help is appreciated.