0

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

3
  • Your question is not well formatted. Please indent your code to fix this. Commented Jul 14, 2016 at 22:01
  • If I just type gnuplot and load the .plt file in a specific directory, it works perfectly fine. But it does not work in bash script. OMG... Commented Jul 14, 2016 at 22:14
  • 2
    Just use gnuplot t-dos.plt in the middle. Commented Jul 14, 2016 at 22:21

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.