1

I want to plot several files just executing a bash script which calls Gnuplot. My idea of a possible bash script is:

#!/bin/bash
gnuplot
plot 'my_first_file.dat' u 1:2
replot 'my_second_file.dat' u  1:2

let us call this bash script gnuplot_script.sh.

When I execute this script via $./gnuplot_script.sh I only get gnuplot open in my terminal without the plots related to the script.

What should I modify in the script in order to have my data plotted? This is my first time in the world of bash scripting.

1 Answer 1

2

I assume the lines

plot 'my_first_file.dat' u 1:2
replot 'my_second_file.dat' u  1:2

Specifying the input for a command does not work as you tried in your script.

You can pass these as input to gnuplot as a "here document".

shell script:

#!/bin/bash
gnuplot << EOF
plot 'my_first_file.dat' u 1:2
replot 'my_second_file.dat' u  1:2
EOF

Or you can write the commands for gnuplot into a separate file and pass the file name as a command line argument to gnuplot, e.g. gnuplot file.plot. (The file does not need to be named .plot.)

You can also create a script that is interpreted by gnuplot instead of a shell.

#!/usr/bin/env gnuplot
plot 'my_first_file.dat' u 1:2
replot 'my_second_file.dat' u  1:2

Make this script executable and run it by typing its name like ./script or /path/to/script as you would run a shell script. (See https://stackoverflow.com/q/15234086/10622916)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .