1

I have this bash script:

#!/bin/bash

foo=42
./test.gp

And this is the gnuplot script (test.gp):

#!/usr/bin/gnuplot

set grid
set title "This is the title (`echo $foo`)"

set terminal png large
set output "/tmp/test.png"
set samples 50, 50
plot [-10:10] sin(x)

I'm led to believe that this should display the title as This is the title (42). But it doesn't. The resulting image looks like this: Resulting plot Also I want to

plot [-10:10] sin(x + `echo $foo`)

But that results in an error:

plot [-10:10] sin(x+)
                    ^
"./test.gp", line 9: invalid expression

I use gnuplot 4.6.

EDIT: moved solution to separate answer as requested in the comments.

4
  • See stackoverflow.com/q/12328603/2604213 for several possibilities. Commented Jan 1, 2016 at 10:51
  • Have you tried putting export foo=42 in your bash script? Also foo=42 ./test.gp works fine. And the solution given in the edited question is also given in the duplicate. Commented Jan 2, 2016 at 17:57
  • @Christoph Mmm. Probably missed that. Thanks! Commented Jan 2, 2016 at 20:35
  • Marking your edit as "Added solution" to a question seems to be not a proper way to close the question as it was reopened by 5 respected men. Move your "EDIT" to an answer below. Commented Jan 3, 2016 at 0:00

1 Answer 1

0

I tried suggestions given here but they did not appear to work for me. (Although I've been advised the solution provided below is actually mentioned there aswell).

I found that changing the script to:

#!/bin/bash


foo=42
gnuplot -e "foo='${foo}'" ./test.gp

works better. Also the GNUPLOT script becomes more readable:

#!/usr/bin/gnuplot

set grid
set title "This is the title (".foo.")"

set terminal png large
set output "/tmp/test.png"
set samples 50, 50
plot [-10:10] sin(x + foo)
Sign up to request clarification or add additional context in comments.

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.