Re: command line assignment

From: Jonathan Vigh <vigh_at_nyahnyahspammersnyahnyah>
Date: Thu, 02 Nov 2006 18:45:24 +0000

Thanks Dennis and Rick,

Rick's suggestion works for me (in bash). So just to clarify - if I
understand this correctly, when I assign an NCL variable to the value of
a shell variable on the command line following Rick's syntax:

ncl nclvar=\"$shellvar\" . . .

is this 'escaping' NCL's interpreter so that the shell can interpret
value of the shell variable? I'm just curious to know what is going on,
because it seems distinctly different from the case given on the example
page where one needs to escape the shell to prevent it from interpreting
a character special to NCL (say '@' when setting an attribute, or '!' in
the c shell):

ncl nclvar=somevalue 'nclvar_at_att=someattribute' . . .

Combining the two cases, then one could set an variable and it's
attributes directly to the values of shell scripts:

shellvar="23"
shellvaratt="number"

ncl nclvar=\"$shellvar\" nclvar_at_att=\"$shellvaratt\"

This does work, so perhaps I've understood this correctly.

However, if shellvaratt is a compound string "number of foos", then I
get an error:

fatal: can't find file "of"

What syntax would I use to assign an NCL attribute to a shell variable
which is a compound string? (I tried various combinations of single and
double quotes, escaping and no escaping, but no luck).

Thanks again for the help - maybe the syntax solutions from Rick and
Dennis can be added to the command line example page for future
enterprising NCL/bash/csh scriptologists who will want to assign shell
variables and compound string attributes on the NCL command line. This
new command line feature seems very useful! My hats off to the NCL
developers who are continually making NCL better and better.

Jonathan

On Thu, 2006-11-02 at 10:27 -0700, Rick Grubin wrote:
> Hi Jonathan,
>
>
> >> I am trying to use the nifty new command line feature of NCL from
> >> a shell script (bash). I'd like to preassign an NCL variable
> >> before calling a script. But I want to assign the NCL variable
> >> (basin) to the value of a shell script variable (shbasin) which
> >> has already been defined previously. If I try this interactively I
> >> get:
> >>
> >> --------------------------------
> >> [vigh_at_euler]$ shbasin="atlantic"
> >> [vigh_at_euler]$ echo $shbasin
> >> atlantic
> >> [vigh_at_euler]$ ncl basin=$shbasin
> >> Copyright (C) 1995-2006 - All Rights Reserved
> >> University Corporation for Atmospheric Research
> >> NCAR Command Language Version 4.2.0.a034
> >> The use of this software is governed by a License Agreement.
> >> See http://www.ncl.ucar.edu/ for more details.
> >> fatal: Assign: atlantic is undefined
> >> fatal:Execute: Error occurred at or near line 1 in
> >> file /tmp/ncl13631.ncl
>
> Please try quoting as follows:
>
> $ shbasin="atlantic"
>
> $ ncl basin=\"$shbasin\"
> Copyright (C) 1995-2006 - All Rights Reserved
> University Corporation for Atmospheric Research
> NCAR Command Language Version 4.2.0.a034
> The use of this software is governed by a License Agreement.
> See http://www.ncl.ucar.edu/ for more details.
> ncl 0> print(basin)
>
>
> Variable: basin
> Type: string
> Total Size: 4 bytes
> 1 values
> Number of Dimensions: 1
> Dimensions and sizes: [1]
> Coordinates:
> (0) atlantic
>
>
>
> -Rick.
> ----
> Rick Grubin NCAR/CISL/VETS
> Visualization + Enabling Technologies
> grubin_at_ucar.edu 303.497.1832
>
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk_at_ucar.edu
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
_______________________________________________
ncl-talk mailing list
ncl-talk_at_ucar.edu
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Thu Nov 02 2006 - 11:45:24 MST

This archive was generated by hypermail 2.2.0 : Wed Nov 08 2006 - 16:43:53 MST