Using variables in gnuplot within a shell script

Hi everybody, please help me with this problem
Suppose I have a script like this to run commands of gnuplot.

#!/bin/sh
lib=$1
old="output/old/$lib.dat"
new="output/new/$lib.dat"

gnuplot << EOF
set logscale x
set logscale y
set size square
set grid
set pointsize 1
plot "< paste $old $new" using 1:4 ti '$lib'
EOF

Since I use logscale, some of my data which have value zero can not be displayed. So I want to write a simple function f(x) that, if the value is 0.000, I will change it to 0.001. Then I use the function on "using f($1):f($4)".
But I am afraid that the variable showing column $1 and $4 will be confused with the 1st and 4th variables of the shell script. Please tell me how I can deal with this problem.

Thank you very much.

Before you start tampering data, could I ask you whether the results you want to display are actually in that domain? Or rather, is the core of your result in the regions where x >> 0, so that you could for instance plot the graph for x > 1?

I am sorry, I deleted some parts of the script to make it simple. I want to display data in the range of [0.001..1000] for both x and y.
I want to write a function like this : f(x) = (x == 0) ? 0.001 : x , then apply for both x and y, i.e. column 1 and 4.
My problem is I can not use $1 and $4 to stand for columns, since it will be confused with the variables of shell script. Please help me.

If you are still stuck on this, you need to use the back slash. f(\$1):f(\$4)

1 Like

When in doubt, replace gnuplot with cat to make sure your plotting script is what you think it is.

1 Like

Yes, my problem still remains. I will try with your instruction. Thanks a lot.