Alternate Interpreters for Script
An answer to this question on Stack Overflow.
Question
I have a script that I'm running on two computers. The first line of the code looks like this:
#!/usr/bin/gnuplot -p
On the second computer, I want to use a version of GNUplot stored at $HOME/bin/gnuplot.
$HOME/bin is included in the second computer's $PATH variable, so I tried starting the script with a generic call to GNUplot:
#!gnuplot -p
but this didn't work because the script then searched for ./gnuplot.
Is there a way to make the header line the same for both computers? I'd prefer that the solution be somehow contained to that one line, without the need for the script to differentiate between the computers or for me to tell it which computer it is on.
Answer
#!/usr/bin/env gnuplot is a more portable way of expressing the interpreter, as noted here and here.
However, this introduces a problem you may not expect.
#!/usr/bin/gnuplot -p
makes a persistent GNUplot window, but running
#!/usr/bin/env gnuplot -p
which would seem like the obvious portable alternative doesn't work.
Some reasons for this are discussed here, but there doesn't really seem to be a way around it: arguments and /usr/bin/env don't really get along.
In the particular case of the -p flag, it is best to use
#!/usr/bin/env gnuplot
and then include the line
set term x11 persist
in your GNUplot script, which will do the same thing.