I want to perform a shell command like this:
convert input.png -pointsize 40 -font "$HOME/Library/Fonts/Droid Sans.ttf" \
-background black -fill red -stroke blue label:"Foo Bar" \
-gravity center -composite output.png
But it's part of a script and some elements are dynamic, which I get from a function. Basically I'm trying something like this:
function GetTextCommands {
echo "-pointsize $2 -font \"$HOME/Library/Fonts/$1.ttf\" \
-background black -fill red -stroke blue label:\"$3\" \
-gravity center -composite"
}
bla=$(GetTextCommands "Droid Sans" 40 "Foo Bar")
convert input.png $bla output.png
However I keep getting quote-related trouble with this. Either it doesn't recognize the Sans.ttf
part, thinking it's a different argument. Or if I put quotes around the $bla
variable in the convert
command, it interprets the entire thing as one argument (which is then deemed invalid, of course).
Note that if I put an echo
before the convert
command to preview what my command line actually looks like, it looks exactly the way I intend. But I realize some quoting may disappear when the entire line is being echo'd.
What's the correct way of going about this?