1

I'm trying to load parameters of Gnuplot from configuration file using bash script and plotting data. The point of this problem is access to these parameters. This is my attempt of solution, but some errors occured.

gnuplot << EOF
values="${params[*]}"
do for [val in values] {
val=sprinf("%s", j)
set $val
}

I got this output:

gnuplot> do for [j in values] {
                              ^
         line 0: invalid complex constant
         line 0: undefined variable: j
gnuplot> set 
             ^
         line 0: Unrecognized option.  See 'help set'.
gnuplot> }
         ^
         line 0: invalid character }

I'm sure, I have multiple strings inside of params array. Thanks

3
  • UPDATE: I've tried "set val" too. Commented May 6, 2014 at 19:56
  • Is there any reason for doing it this way and not having a configuration file and loading it with load 'config.gp'? Commented May 6, 2014 at 20:29
  • Yes, it's my task, I've got structure of configuration file (for Gnuplot and other stuff) and I'm creating a script to handle this file. Actually, it's not my code, I found it here at stackexchange but it made sence for me, so I used it. Commented May 6, 2014 at 23:11

1 Answer 1

0

Your gnuplot version is too old. The iteration structure do for is supported only since version 4.6.

Then, the following works fine:

#!/bin/bash
params[0]='grid'
params[1]='xrange[0:10]'

gnuplot -persist << EOF
values="${params[*]}"
do for [val in values] {
    eval('set '.val)
}
plot x
EOF

But that works only, if the array entries don't contain any white spaces. Usually, you would create a configuration file with the content

set grid
set xrange [0:10]

and load this with load 'config.gp'.

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.