Lei Zhang
Lei Zhang

Reputation: 103

gnuplot load does not work in a bash script

I have a bash script to automate plotting using gnuplot, however the load command within gnuplot does not work in the bash script. The command simply gets stuck.

Here is my bash script:

#!/bin/bash

for k in _1 +1 _2 +2 _3 +3 _4 +4 _5 +5 _6 +6
do
    cd $k/surface

    for i in s ss
    do
        cd $i
        for j in `ls -d */`
        do
            if [ "$j" != "unrelax/" ]; then
                cd $j/spin
                echo $k$i$j

                gnuplot 
                load 't-dos.plt'
                exit            

                cd ../../
            fi
        done     
        cd ..
    done     
    cd ../../
done 

t-dos.plt contains:

cat > t-dos.plt << eof
fermi=$(head -6 DOSCAR | tail -1 | awk '{print $4}')
plot 't-dos' u (\$1-fermi):2 w l
replot 't-dos' u (\$1-fermi):3 w l
set term post enhanced color
set output 't-dos.ps'
rep
eof

My output is like:

entering the gnuplot and stay there forever

Upvotes: 0

Views: 750

Answers (2)

Vinicius Placco
Vinicius Placco

Reputation: 1731

There is two things you could do. The first was suggested in the comments:

gnuplot t-dos.plt

The other would be using a "here document":

gnuplot << GNUPLOT

load t-dos.plt

GNUPLOT

Upvotes: 0

bodgit
bodgit

Reputation: 293

When your bash script runs gnuplot, it's now sat waiting for gnuplot to exit before continuing any further, at which point it will then try and run a command called load (and probably fail). gnuplot is itself sat waiting for input giving the illusion that your script is paused or hanging.

What you're expecting to happen is for any text after the gnuplot line to be magically entered into the gnuplot interface, bash scripts don't work that way.

Upvotes: 2

Related Questions