How to keep quotes in Bash arguments?

zlack picture zlack · Nov 3, 2009 · Viewed 91.1k times · Source

I have a Bash script where I want to keep quotes in the arguments passed.

Example:

./test.sh this is "some test"

then I want to use those arguments, and re-use them, including quotes and quotes around the whole argument list.

I tried using \"$@\", but that removes the quotes inside the list.

How do I accomplish this?

Answer

Chris Dodd picture Chris Dodd · Nov 3, 2009

using "$@" will substitute the arguments as a list, without re-splitting them on whitespace (they were split once when the shell script was invoked), which is generally exactly what you want if you just want to re-pass the arguments to another program.

What are you trying to do and in what way is it not working?