Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Passing arguments to gnuplot

6,881 views
Skip to first unread message

Yipkei Kwok

unread,
Oct 26, 2009, 5:11:35 PM10/26/09
to
hi,

Is it possible to pass arguments into a GNUPLOT script?

Some folks suggest that shell environment variables may be used for
this purpose. Does anyone have an example, or two?

Thank you!

Hans-Bernhard Bröker

unread,
Oct 26, 2009, 7:06:00 PM10/26/09
to
Yipkei Kwok wrote:

> Is it possible to pass arguments into a GNUPLOT script?

[A side remark: the name of the program is "gnuplot". Not GNUplot, nor
GnuPlot, nor GNUPLOT.]

> Some folks suggest that shell environment variables may be used for
> this purpose. Does anyone have an example, or two?

The time-honoured method is by back-tick substitution:

set variable=`echo $VARIABLE`

This runs the echo command in a sub-shell, and puts the result into a
gnuplot variable.

Yipkei Kwok

unread,
Oct 26, 2009, 10:08:00 PM10/26/09
to
Thank you! It works!!

Just a remark. It should be

set variable `echo $VARIABLE`

And if the parameter is text, it should be

set variable "`echo $VARIABLE` "

On Oct 26, 5:06 pm, Hans-Bernhard Bröker <HBBroe...@t-online.de>
wrote:

Juergen Wieferink

unread,
Oct 27, 2009, 3:00:20 AM10/27/09
to
> Is it possible to pass arguments into a GNUPLOT script?
>
> Some folks suggest that shell environment variables may be used for
> this purpose. Does anyone have an example, or two?

It is probably easier to use the "-e" command line option of the
more recent versions of gnuplot to set a variable:

$ gnuplot -e 'var=value' script.gp


Juergen



Laurianne Gardeux

unread,
Oct 27, 2009, 9:54:04 AM10/27/09
to
Le Mon, 26 Oct 2009 14:11:35 -0700, Yipkei Kwok a écrit :

> Is it possible to pass arguments into a GNUPLOT script?


Sometimes, I use gnuplot in a here-document:

#!/bin/sh
gnuplot <<EOF
[...] "$VARIABLE" [...]
EOF

sfeam

unread,
Oct 27, 2009, 2:03:25 PM10/27/09
to
Yipkei Kwok wrote:

> Thank you! It works!!
>
> Just a remark. It should be
>
> set variable `echo $VARIABLE`
>
> And if the parameter is text, it should be
>
> set variable "`echo $VARIABLE` "
>


Or, if you are doing this inside gnuplot itself:

variable = "`echo $VARIABLE`"

In other words, you don't need to load the value of the environmental
variable as part of the calling script, you can let gnuplot itself
retrieve the current value.

0 new messages