2

I have been creating a quick bash script that will generate some resource numbers and display them via gnuplot. I ran into an issue the second I changed the filenames in the gnuplot command to reflect a variable my script sets up for file location. Example code is below. Any idea why I am having this issue? I am guessing that gnuplot is not expanding my variable I setup, I just cannot figure out what I need to change. Thank you.

testFile=/var/log/testing.log
testFileTwo=/var/log/testingTwo.log
gnuplot -persist -e 'set xlabel "TIME"; set ylabel "PERCENT" ; set yrange [0:100]' -e 'plot ${testFile} smooth bezier, ${testFileTwo} smooth bezier'

As soon as I run this script, I receive the following error.

plot ${testFile} smooth bezeri, ${testFileTwo} smooth bezier
      ^
line 0: invalid complex constant
Cyrus
  • 84,225
  • 14
  • 89
  • 153
IT_User
  • 729
  • 9
  • 27

1 Answers1

3

Bash does not expand variables inside ' single quotes. If you use " double quotes after the second -e, bash will expand ${testFile} and ${testFileTwo} before passing the resulting string to gnuplot.

EDIT: use -e "plot '${testFile}' ...", to make sure that plot receives the name inside quotes.

joranvar
  • 490
  • 5
  • 9
  • I have no idea how I missed that. Thank you! Ran into another issue right away from gnuplot saying "/" is an invalid expression. But that is another issue I will start looking down. Thank you again for the quick response. – IT_User Dec 07 '15 at 20:43
  • I will accept your answer in 5 minutes once I am allowed to. – IT_User Dec 07 '15 at 20:44
  • My bad. You should use single quotes again around the filename within that. I'll update my answer. – joranvar Dec 07 '15 at 20:44