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.

Mausy5043
  • 906
  • 2
  • 17
  • 39
  • See http://stackoverflow.com/q/12328603/2604213 for several possibilities. – Christoph Jan 01 '16 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. – Christoph Jan 02 '16 at 17:57
  • @Christoph Mmm. Probably missed that. Thanks! – Mausy5043 Jan 02 '16 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. – John_West Jan 03 '16 at 00:00

1 Answers1

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)
Community
  • 1
  • 1
Mausy5043
  • 906
  • 2
  • 17
  • 39