My goal is to call a script with an variable as it's arguments. For example, I have the following two files:
print_args.sh:
echo "Length: $#"
for i in "$@"; do echo "$i"; done
caller.sh:
ARGS="foo \"Hello, World\" bar"
./test.sh $ARGS
When I run:
./print_args.sh foo "Hello, World" bar
print_args.sh
get's called with 3 arguments:
Length 3
foo
Hello, World
bar
However, when running it via caller.sh
instead I get 4 args:
Length: 4
foo
"Hello,
World"
bar
What's going on here? How can I get caller.sh
to perform as expected?
Note: I don't have control over ARGS
it's passed in as an environment variable.