[Thread Prev][Thread Next][Index]
Re: [ferret_users] accessing environment variables within ferret
Hi Keith,
Here's the short answer for how to import an environment variable:
let result = spawn("echo $CASE")
Note that this defines a string variable, not a symbol. If you'd rather
have a symbol instead, you can do this:
define symbol result "`spawn("echo $CASE")`"
And here's a more in-depth example, showing delayed-evaluation and variable
re-use in Ferret:
% setenv ENV1 keith
% setenv ENV2 andrew
% ferret
NOAA/PMEL TMAP
FERRET v6.67
Linux rh5 (gfortran) 2.6.18-238.1.1.el5P - 02/11/11
15-Feb-11 17:51
yes? let result = spawn(command)
yes? let command = "echo $ENV1"
yes? let keep_result = "`result`"
yes? list result, keep_result
X: 1
Column 1: RESULT is SPAWN(COMMAND)
Column 2: KEEP_RESULT is "keith"
RESULT KEEP_RESULT
I / *: "keith" "keith"
yes? let command = "echo $ENV2"
yes? list result, keep_result
X: 1
Column 1: RESULT is SPAWN(COMMAND)
Column 2: KEEP_RESULT is "keith"
RESULT KEEP_RESULT
I / *: "andrew" "keith"
Cheers,
Andrew
On Tue, 15 Feb 2011, Keith Lindsay wrote:
Hi,
Is there a way to set a ferret symbol to be equal to an environment variable
that had been set in the environmet from which ferret was run?
It looks like the environment variables are being inherited in the shell
created by the spawn command, so "spawn echo $CASE" is returning the value of
$CASE. But I haven't figure out the magic incantation to get the result of
this into a ferret symbol.
The following doesn't work, but indicates what I'm trying to accomplish:
define symbol CASE = `spawn echo $CASE`
Any suggestions on how to get this to work, or pointers to another mechanism
to retrieve an environment variable within ferret?
Thanks, Keith
******************************************************************
Keith Lindsay http://www.cgd.ucar.edu/oce/klindsay/
email: klindsay@xxxxxxxx phone: 303-497-1722 fax: 303-497-1700
[Thread Prev][Thread Next][Index]
Contact Us
Dept of Commerce /
NOAA /
OAR /
PMEL /
Ferret
Privacy Policy | Disclaimer | Accessibility Statement