3

Hello I want to plot smth using gnuplot in a bash script so I have:

#!/bin/bash
//myscript
gnuplot -persist <<-EOFMarker
        plot 'd.csv' using 3:xtic(1) with boxes notitle, 'd.csv' using 0:($3+100):3 with labels
EOFMarker

my problem is that the script substitute ($3+100) from bash variable (nothing+100) not from gnuplot (each value from 3rd column + 100).. how can I change the script in order to use the variable from gnuplot? thanks very much

1
  • no, it substitute $3 from bash script parameters $1,$2,$3 instead of the 3rd column from 'plot' command Commented May 8, 2016 at 20:58

2 Answers 2

2

It should work, $3 is properly empty, consider this:

#!/bin/bash
set a b world
cat <<-EOF
hello $3
EOF

Will output hello world. If you want to send literal $3 to the command you will need to escape the dollar sign:

#!/bin/bash
set a b world
cat <<-EOF
hello \$3
EOF
Sign up to request clarification or add additional context in comments.

3 Comments

no, it substitute $3 from bash script parameters $1,$2,$3 instead of the 3rd column from 'plot' command
the variables like ./myscript.sh $1 $2 $3 ... do you understand me now?
@TopGamesa-Z If you want to use literal $3 in here docs you will need to escape the dollar sign: \$3
1

Use the column function, then you must not care about escaping: $2 is a shortcut for column(2).

gnuplot -persist <<-EOFMarker
    plot 'd.csv' using 3:xtic(1) with boxes notitle, 'd.csv' using 0:(column(3)+100):3 with labels
EOFMarker

BTW: when plotting labels you can use the offset option to specify an offset e.g. in character units:

gnuplot -persist <<-EOFMarker
    plot 'd.csv' u 0:3:xtic(1) w boxes t '', '' u 0:3:3 w labels offset 0, char 1
EOFMarker

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.