Using display in bash script

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
porphyry5
Posts: 12
Joined: 2011-05-22T10:06:09-07:00
Authentication code: 8675308

Using display in bash script

Post by porphyry5 »

If I do

Code: Select all

display "/tmp/Agoseris7-8.jpg" "/tmp/Albino5-2.jpg" "/tmp/Albino5-4.jpg" "/tmp/Arnica7-7-2.jpg"
all is well.
But if I do

Code: Select all

x='"/tmp/Agoseris7-8.jpg" "/tmp/Albino5-2.jpg" "/tmp/Albino5-4.jpg" "/tmp/Arnica7-7-2.jpg"'
display $x
it fails, as does also

Code: Select all

display "$x"
display <<< $x
display <<< "$x"
echo "$x"|display
How can I deliver a string of file-paths in a variable for "display" to display?
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Using display in bash script

Post by anthony »

This is a bash scripting problme in that quotes stored in variables are not parsed by the shell (quote parsing is already done when variables are substituted).

You will need to either use a bash array for each argument, or use and 'eval' to get the shell to parse the result a second time.

WARNING; using eval is dangerous as it provides many ways for crackers to break into your script if used publically (from the web). That does not mean you can not use it, it means you need a deep understanding of its use and dangers, and a through parsing of inputs into the program, though that is something that should be done for any online program regardless!!!

Of course as you are using display the web is not an option, but if it is for a public 'kiosk' terminal, then you still need to watch out.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
porphyry5
Posts: 12
Joined: 2011-05-22T10:06:09-07:00
Authentication code: 8675308

Re: Using display in bash script

Post by porphyry5 »

Thank you for the info, eval isn't a problem, this is only for my own personal computer, no one else has access to it.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Using display in bash script

Post by anthony »

You say that now, but believe me when I say, --- Things change! :-)
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply