I've been writing one-line bash scripts on the command line since 1989.  These usually have the form:for name in 1 2 3; do wc $name.txt; doneNow I'm trying to do some image manipulation with GIMP, using a script that takes two filenames for arguments.  Here's something that gives me a valid command line:/Applications/GIMP.app/Contents/MacOS/GIMP -b '(script-fu-overlay png0004.tif png0000.tif) (script-fu-overlay png0004.tif png0001.tif) (script-fu-overlay png0004.tif png0002.tif) (script-fu-overlay png0004.tif png0003.tif)'It was generated with the help of a typical one-liner:X=\'$(for name in 0 1 2 3; do echo \(script-fu-overlay \png0004.tif\ \png000$name.tif\\) ; done)\'But...and here is my question:echo /Applications/GIMP.app/Contents/MacOS/GIMP -b $Xgives me the exact command line above, but when I run/Applications/GIMP.app/Contents/MacOS/GIMP -b $XI get errors about not being able to open filenames that have quotes around them, but when I run/Applications/GIMP.app/Contents/MacOS/GIMP -b $Xeverything works.  My real goal is to understand whether it's possible for me to write a one-liner without resorting to variables at all.  Something like:/Applications/GIMP.app/Contents/MacOS/GIMP -b \'$(for name in 0 1 2 3; do echo \(script-fu-overlay \png0004.tif\ \png000$name.tif\\) ; done)\'But that fails in apparently the same way that/Applications/GIMP.app/Contents/MacOS/GIMP -b $Xfails.
Confusion about bash command vs. variable substitution
bash;command substitution;variable substitution
Yes you can do it on the command line without resorting to shell variables./Applications/GIMP.app/Contents/MacOS/GIMP -b $(for name in 0 1 2 3; do echo \(script-fu-overlay \png0004.tif\ \png000$name.tif\\) ; done)Note that we need to do away with the escaped single quotes since we are not doing an eval here. Only thing that is needed are the double quotes around the command expansion $(...) to prevent word split from happening PLUS pass the result as one single argument to gimp.