[ncl-talk] Pass a string to ncl via csh that contains a space
Dave Allured - NOAA Affiliate
dave.allured at noaa.gov
Thu Mar 24 16:45:09 MDT 2016
Annie,
The shell quoting is tricky, especially in combination with a shell
variable. NCL needs to receive both double quotes and spaces within a
single shell "word" as a single command argument.
The following uses two different quoting methods for different parts of the
argument "word". There is more than one way to do this.
The square brackets in the NCL print statement are just for show.
mac56:~/temp/ncl 32> cat qtest.ncl
begin
print ("["+title+"]")
end
exit
mac56:~/temp/ncl 33> cat quote1.csh
#!/bin/csh
set title = "This is a title"
ncl qtest.ncl title=\""$title"\"
mac56:~/temp/ncl 34> ./quote1.csh
NCAR Command Language Version 6.3.0
(0) [This is a title]
--Dave
On Tue, Mar 22, 2016 at 2:37 PM, Annie Seagram <aseagram at sonomatech.com>
wrote:
> I have seen a number of discussions regarding passing strings as variables
> to ncl scripts from csh (e.g. here
> <https://www.ncl.ucar.edu/Support/talk_archives/2010/2386.html)>) and I
> have read through the NCL systems interactions page
> <https://www.ncl.ucar.edu/Applications/system.shtml#SHCLA>, but I can’t
> figure out how to pass a string that has a space in it.
>
>
>
> For example, on the command line one could specify:
>
> ncl year=2014 month=5 'title="This is a title"' myscript.ncl
>
>
>
> However, in a csh script how does one pass the title as a variable? It
> seems to crash when there are spaces. e.g.
>
>
>
> This works:
>
> #!/bin/csh -f
>
> set title = “Thisisatitle”
>
> ncl year=2014 month=5 title= \"{$title}\" myscript.ncl
>
>
>
> This fails:
>
> #!/bin/csh -f
>
> set title = “This is a title”
>
> ncl year=2014 month=5 title= \"{$title}\" myscript.ncl
>
>
>
> The error:
>
> Missing }.
>
> Missing }.
>
>
>
> Is there a way to escape this behavior? I’d like to avoid setting
> environment variables.
>
>
>
> Thanks for your help.
>
>
>
> -annie
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20160324/d4345dd0/attachment.html
More information about the ncl-talk
mailing list