0

Can I use a here document to pass a gnuplot script to gnuplot and also have commandline line arguments passed to gnuplot?

In my bash file, I would normally write:

#!/bin/bash
#set up code in here...
gnuplot -c script.gp $first $second

But I want to have everything in one bash file, so I've done

#!/bin/bash
#set up code in here...
gnuplot -c <<- EOF
do for [j=0:ARG1] {
   do for [i=4:ARG2] {
      plot '${data}' index j using 2:i with lp
   }
}
EOF $first $second

but I get the infamous warning: here-document at line 87 delimited by end-of-file (wantedEOF')`` error. $data, $first, and $second are defined earlier in the bash script.

If I put the command line arguments on the next line, to leave the EOF alone, I get command not found errors associated with the value of $first.

My here document is indented only with tabs. There is no trailing whitespace.

1

You could try something like:

gnuplot -c /dev/stdin "$first" "$second" <<-EOF
do for [j=0:ARG1] {
   do for [i=4:ARG2] {
      plot '${data}' index j using 2:i with lp
   }
}
EOF

Gnuplot complains

line 4: No previous filename

but then I get the same error when using a script file, so it's probably something to do with the code being incomplete.

0

This is one solution: get rid of the arguments, and do the replacement manually.

#!/bin/bash
#set up code in here...
gnuplot <<- EOF
do for [j=0:${first}] {
   do for [i=4:${second}] {
      plot '${data}' index j using 2:i with lp
   }
}
EOF

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.