I’m trying to get quoted parameters of a bash script to safely be received by a nested script. Any ideas?
test.sh
#!/bin/bash echo $* bash myecho.sh $*
myecho.sh
#!/bin/bash echo $1 echo $2 echo $3 echo $4
Sample:
bash test.sh aaa bbb ''ccc ddd''
Result:
aaa bbb 'ccc ddd' aaa bbb 'ccc ddd'
Wanted result
aaa bbb 'ccc ddd' aaa bbb ccc ddd
Note the ‘$@’ construct is not bash specific and should work with any POSIX shell (it does with dash at least). Note also that given the output you want, you don’t need the extra level of quoting at all. I.E. just call the above script like: