How can I preserve single and double quotes when running a comm开发者_C百科and using exec?
#!/bin/sh
CMD="erl -eval 'erlang:display("foo")'"
exec $CMD
Tried with backslashes, but didn't help. For example, if I do what it would sound ovious to me:
#!/bin/sh
CMD="erl -eval 'erlang:display(\"foo\")'"
echo $CMD
exec $CMD
I get as output of the echo
exactly what I want, but the command is not executed correctly when using exec
.
I'm working on Snow Leopard.
Any help?
Try using an array:
CMD=(erl -eval 'erlang:display("foo")')
echo "${CMD[@]}"
"${CMD[@]}"
It will work if you use eval
instead of exec
, if this is the last thing in your script it won't make a huge difference operationally...
#!/bin/sh
CMD="erl -eval 'erlang:display(\"foo\")'"
echo $CMD
eval $CMD
精彩评论