Page 1 of 1

Using display in bash script

Posted: 2011-07-19T17:17:55-07:00
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?

Re: Using display in bash script

Posted: 2011-07-19T17:26:49-07:00
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.

Re: Using display in bash script

Posted: 2011-07-19T19:59:57-07:00
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.

Re: Using display in bash script

Posted: 2011-07-19T21:35:06-07:00
by anthony
You say that now, but believe me when I say, --- Things change! :-)