[Thread Prev][Thread Next][Index]

Re: [ferret_users] accessing environment variables within ferret



Keith Lindsay a écrit :
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?
Hi Keith,
You can use the SPAWN function rather than the command.

##########################
yes? show function spawn
SPAWN(STR)
   execute a system command
   STR: Unix command string (STRING)

##########################
A simple example could be:
yes? define symbol USER=`SPAWN("echo $USER")`

##########################
I often use the following lines to count
the number of lines of a large text file to be read

def sym nblines=`SPAWN("cat ($01) | wc -l")`
def axis/x=1:($nblines):1 vector_length
def grid/x=vector_length vector_grid
file/var=xpos,ypos/g=vector_grid "($01)"

##########################
Another one to read legends from a text file:
let list_textlegend=SPAWN("cat veget_type.txt")
Note that when you use a variable you don't need to use an
embedded expression (ie with characters `...`).

##########################
An one from an answer from Andrew Wittenberg
with a awk command that needs single quote
yes? let a = SPAWN("echo Hello ferreters | awk '{print $2}'")
yes? list a
            VARIABLE : SPAWN("echo Hello ferreters | awk '{print $2}'")
            X        : 1
       "ferreters"

Happy ferreting.
Patrick

--
LSCE/IPSL, Laboratoire CEA-CNRS-UVSQ
Data Analysis and Visualization Engineer
IPSL Global Climate Modelling Group
--



[Thread Prev][Thread Next][Index]
Contact Us
Dept of Commerce / NOAA / OAR / PMEL / Ferret

Privacy Policy | Disclaimer | Accessibility Statement