I have a bash script that launches another bash script and needs to pass multiple parameters (which may contain spaces). In the launcher script I am defining the parameters as a single string, escaping any spaces as necessary. However I can't seem to get the parameters passed properly.
Here is my test setup to replicate the problem I am having:
test.sh
while [[ $# -gt 0 ]]; do
echo "${1}"
shift
done
launcher.sh
#!/bin/bash
args="arg1 arg2 arg\ 3 arg4"
./test.sh ${args}
Running test.sh directly from command line (./test.sh arg1 arg2 arg\ 3 arg4)
arg1
arg2
arg 3
arg4
Running launcher.sh
arg1
arg2
arg\
3
arg4
I've tried multiple variations of double quotes, read, IFS, etc, but I can't seem to get the results I am looking for. Any guidance would be appreciated.