How can I store an argument vector with an argument containing spaces in a bash variable?

For example, I want 2.sh to print b c



ARGV='a "b c"'
./2.sh $ARGV



echo $2

You should use an array instead of a string:

args=("a" "b c")
./2.sh "${args[@]}"

When the array expansion is quoted, each element of the array is properly expanded.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.