mike628 mike628 - 4 months ago 24
Bash Question

Quote argument strings Shell

Can I quote arguments that have spaces or special chars in the command line? If not, how is this handled. We have one argument that is a multiword string. I'm sure this has been asked many times, but I cant find it.

./myscript name=bob occupation=guy who does stuff

Answer

You can use quotes. Something like:

$ var='abc def'
$ echo "$var"
abc def

You can read more here.

Your case example (note I'm calling the script that needs the multiword string from the another script in this example):

sh ./test.sh 'this is a test'

test.sh contains echo $1 and prints this is a test. Hope this solution works.