Re: command line assignment

From: Rick Grubin <grubin_at_nyahnyahspammersnyahnyah>
Date: Thu, 2 Nov 2006 12:50:18 -0700

Hi Jonathan,

> 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?

The backslash ('\') character is a quoting character: it preserves
the literal value of the next character that follows. In the case
above, it preserves the meaning of the double quotes (").

Single quotes (') preserves the literal value of each character
within those quotes.

Double quotes (") preserves the literal value of all characters
within the quotes (excepting $, `, ', and \).

That's the quick and dirty explanation of quoting for sh/ksh/bash.

In the case we're discussing, since '$' retains its meaning,
$shellvar will expand to what you set it to, and then is enclosed
within double quotes so it appears as a string to NCL.

> 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).

With variables that contain spaces, you'll need two sets of quotes, as:

% myvar="number of foos"
% ncl myVar=\""$myvar\""

This syntax will yield a double quote followed by "$myvar" followed
by a double quote, which yields a double quote followed by what
$myvar evaluates to followed by a double quote. This is the more
general and exhaustive case.

> 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.

An example has been added (per Dennis' and your suggestion). It uses
the idiom of the more general case.

I would suggest you do not become a scriptologist -- madness and
insanity follow that path.

Visualization + Enabling Technologies 303.497.1832

ncl-talk mailing list
Received on Thu Nov 02 2006 - 12:50:18 MST

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