Search code examples
gnuplot

Gnuplot - Command Substitution and Script Name


I'm using Gnuplot as my back-end plotter and I often use the following setup :

#Filename : my_plot.gnuplot
set terminal pdfcairo [my_options]
set output 'my_plot.pdf'
....

coupled with a Makefile :

%.pdf : %.gnuplot
    gnuplot $<

My question is simple : is there a command / way to refer to the name of the script inside the script (the equivalent of bash's $0) and set the output with a clever sprintf or equivalent ?


Solution

  • You cannot access the script name from gnuplot, but you can give a parameter when calling the script, which should work fine, especially when using Makefiles.

    %.pdf: %.gnuplot
        gnuplot -e "scriptname='$<'" $<
    

    In the plot file, this could be used with a command such as:

    set output scriptname
    

    Or from the command line:

    gnuplot -e "scriptname='my_plot.gnuplot'" my_plot.gnuplot