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; done
Now 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 $X
gives me the exact command line above, but when I run
/Applications/GIMP.app/Contents/MacOS/GIMP -b $X
I 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 "$X"
everything 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 $X
fails.
png000$name.tif
topng000${name}.tif
gimp
doesn't know. The shell removes the single quotes and passes the whole string between them as one parameter togimp
.gimp
doesn't know how this parameter has been composed.