0

I have the following command stored in a shell script variable.

x='gs -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=output3.pdf /usr/share/ghostscript/8.70/lib/viewjpeg.ps -c "(PO-31649-1.jpg) viewJPEG showpage (PO-31649-2.jpg) viewJPEG showpage (PO-31649-3.jpg) viewJPEG showpage"'

When I execute the gs command directly on the command prompt, it creates output3.pdf. However, when assign that command to a shell variable and execute the script, it errors out as follows:

GPL Ghostscript 8.70: Unrecoverable error, exit code 1

How do I execute a command stored in a variable? Any help would be appreciated.

  • This is [BashFAQ #50](http://mywiki.wooledge.org/BashFAQ/050) – Charles Duffy Jan 26 '17 at 19:17
  • @CharlesDuffy Thank you very much for the links!! That is exactly what I was looking for. The Eval command. Please mark this is as duplicate. – user7475543 Jan 26 '17 at 19:22
  • To be clear, `eval` is generally not the best/preferred/ideal way to do this. Depending on your goals, either a function or an array will generally be a better fit; the aforementioned FAQ will allow narrowing down which applies to the present case. – Charles Duffy Jan 26 '17 at 20:31
  • [BashFAQ #48](http://mywiki.wooledge.org/BashFAQ/048) goes into detail regarding why use of `eval` is generally considered bad practice. – Charles Duffy Jan 26 '17 at 20:32

0 Answers0