1

I want to plot a set of data stored in different files:

file.txt_100K
file.txt_200K
file.txt_300K

I came up with the following bash script:

  1 #!/bin/bash
  2 
  3 filename=file.txt_
  4 
  5 gnuplot <<- EOF
  6     set term png
  7     set output "plot.png"
  8     plot '"$filename"100K' w lp,\
  9                 '"$filename"200K' w lp,\
 10                 '"$filename"300K' w lp
 11 EOF

The following is the output after running the script:

         line 0: warning: Cannot find or open file ""file.txt_"100K"
     line 0: warning: Cannot find or open file ""file.txt_"200K"
     line 0: warning: Cannot find or open file ""file.txt_"300K"
     line 0: No data in plot

I was hoping that in lines 8, 9 and 10 of the bash script the following would be the case:

'"$filename"100K' == 'file.txt_100K'
'"$filename"200K' == 'file.txt_200K'
'"$filename"300K' == 'file.txt_300K'

What change should I make to the lines 8, 9, 10 to get the above desired result ? Thanks in advance.

1

From the man page, bash here-documents only do

parameter expansion, command substitution, and arithmetic expansion,

so it doesn't do quote removal. Use lines like

plot '${filename}100K' w lp,\

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.