I have a very simple script:
#!/bin/bash
gnuplot << EOF
set term postscript portrait
set output 'out.ps'
plot 'data_file' u 3:($2==0.0 ? $2:1/0)
EOF
where data_file looks like this:
O4 -1.20 -0.33 -5.20
O9.5 -1.10 -0.30 -3.60
B0 -1.08 -0.30 -3.25
B0.5 -1.00 -0.28 -2.60
B1.5 -0.90 -0.25 -2.10
B2.5 -0.80 -0.22 -1.50
B3 -0.69 -0.20 -1.10
....
I have tried several combinations and I still get the same error always:
gnuplot> plot 'S-K_data' u 3:(==0.0 ? :1/0)
^
line 0: invalid expression
As you can see, it’s not reading the $2 characters and I just can’t figure out why.
In an unquoted here doc, variables are expanded. Try
or
Which you choose is a matter of personal preference (you can use any quoting mechanism, so
EOF""works, but the two above are the most common). When the heredoc delimiter is unquoted, the shell is expanding$2to the second parameter passed to the script. (Try calling the script with 2 arguments.) When the heredoc delimiter is quoted, no such expansion takes place.