I am automating a task to create small graphs using gnuplot. And I need to pass the column number from the datafile that is to be plotted
pfile=system(\"echo
This is an alternative to @EWCZ's answer. Any variable initialized using the system
command is treated as a string: in your case, colnum="2"
(with quotes). You can transform it to an integer by adding zero:
# first option
plot pfile using 4:(column(colnum+0))
# second option
colnum = system("echo $colnum") + 0
plot pfile using 4:(column(colnum))
As a side note, your task could be more flexible (easier to automate) by using @Christoph's answer; better if you have gnuplot 5.0
because you can pass arguments to a gnuplot script directly