How do I pass the -e variable to gnuplot?
I want to define the output of gnuplot which is a png file. How to determine filename in gnuplot.
#This lines and also Traffic$j are define on my bash file.
# Traffic$j is the name of file and that is valid. Traffic$j is on the loop
# j is loop index
.
.
fileName=Traffic$j
.
.
I am trying this:
gnuplot -e "filename=${!fileName}" plotFile
But I am going with this error:
line 0: constant expression required
I'm trying ruah's idea:
gnuplot -e "filename = '${!fileName}'" plotFile
But I am warning this warning:
"plotFile", line 12: warning: skip data file without valid points
line 12? check out my last line script.
How do I pass a variable to -e to gnuplot?
Update: My plotFile:
set terminal png size 720,450 enhanced font "H,11"
set output filename . '.png'
plot '../_numXY' using 2:3:(sprintf('%d', $1)) with labels offset 0,1 point pointtype 7 ps 2 lc rgb "green" notitle, \
filename using 1:2:($3-$1):($4-$2) with vectors linewidth 6 lc rgb "blue" notitle #line 12
source to share
The problem is not so much how to pass the variable, but how to quote the string. If, for example, $j
there is 3
, and $Traffic3
- file.txt
, then what you go to -e
is equal filename=file.txt
to when you need to pass something like filename = "file.txt"
or filename = 'file.txt'
. So:
gnuplot -e "filename = '${!fileName}'" plotFile
Edited to add: In a comment, you write:
thanks, $ Traffic3 is not file.txt. or better to say that I don't have $ Traffic3, but I have Traffic3. Traffic3 is not a parameter. This is the name of the file itself and is not related to other thing like file.txt
This means that you don't have to write ${!fileName}
, but rather $fileName
. The notation ${!fileName}
means something like, "OK, so the value $fileName
is the name of another variable. Give me the value of that variable." So you just want:
gnuplot -e "filename = '$fileName'" plotFile
source to share