0

I am learning pass BASH list to Gnuplot without generate an intermediate file. The answer I found was very useful (by Christoph at Set parameters of Gnuplot from array in bash script). And the code is below.

I am confused about two symbols. One is " in values="${params[]}*. The other is . in eval('set '.val). I did not find the syntax in the manual. Could you tell me what they are for?

### Code
#!/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
####
1
  • You'll find a full list of operators, like the ., in the gnuplot manual in the Chapter Expressions -> Operators. Commented Jul 23, 2015 at 6:32

1 Answer 1

1

There here document is constructed from shell variables. ${params[*]} is bash code for "all elements in the array params concatenated into a string". It's not all gnuplot code.

Replace gnuplot -persist with cat to see what gnuplot sees:

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

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

resulting in:

values="grid xrange[0:10]
do for [val in values] {
    eval('set '.val)
}
plot x

values="grid xrange[0:10] is a variable assignment:

gnuplot> values="grid xrange[0:10]
gnuplot> print values
grid xrange[0:10]

. is string concatenation:

gnuplot> print "foo" . "bar"
foobar

So the result is that set grid and set xrange[0:10] are evaluated by gnuplot as if you had typed them in manually.

Sign up to request clarification or add additional context in comments.

3 Comments

I know the meaning of ${params[*]}. But I don't understand the function of symbol " before it.
It starts a string literal in gnuplot. gnuplot allows but does not require a second " to close it
Thanks, guys! I got it. String literal without closing double quote is really not a good syntax.

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.