0

I made a script as following to plot with GnuPlot.

#!/usr/bin/gnuplot
#file: myplot
set term svg;
set out 'figfile.svg';
plot './datafile.dat' with lp;
set term wxt 0;
set out;

So, I can create a figure file as

$./myplot

However, I have to edit the script to replace 'figfile.svg' and 'datafile.dat' manually. Can I modify this script and use the following format to create a figure file?

$./myplot datafile.dat figfile.svg

Thanks all.

HXGuo
  • 45
  • 1
  • 1
  • 6
  • For other options see [How to pass command line argument to gnuplot?](http://stackoverflow.com/q/12328603/2604213). – Christoph Jan 21 '14 at 10:04

1 Answers1

1

You could wrap your call to gnuplot with a shell script:

#!/bin/sh

gnuplot <<EOF
set term svg
set out '$1'
plot '$2' with lp
set term wxt 0
set out
EOF

The shell would substitute $1 and $2 in the script with the first and second command line parameters.

larsks
  • 277,717
  • 41
  • 399
  • 399