Re: command line variable string

From: David Hebert <david.hebert_at_nyahnyahspammersnyahnyah>
Date: Fri Feb 03 2012 - 08:19:45 MST

Excellent! Both David and Andrea's methods worked great. Thank you both
for your answers!

David

On 02/03/12 08:29, David Brown wrote:
> Not to argue whether setting environment variables is better or worse than using command line arguments, the ncl syntax requires double quotes around a string literal value. That is the source of the error. You can make your script work in a csh type shell by changing your script like this:
>
> foreach i (*.nc)
> echo $i
> ncl plot_aice.ncl fname=\"$i\"
> end
>
> An equivalent bash script would be:
>
> for i in *.nc
> do
> echo $i
> ncl plot_aice.ncl "fname = \"$i\""
> done
>
> -dave
>
> On Feb 3, 2012, at 6:19 AM, David Hebert wrote:
>
>> I have a bunch of daily output netcdf files I would like to make plots of. For short
>>
>> 700_cice.2011-12-29.nc
>> 700_cice.2011-12-30.nc
>> 700_cice.2011-12-31.nc
>>
>>
>> My original intent was to pass the file name as a command line variable, then parse for dtg. When I do the following:
>>
>> foreach i (*.nc)
>> echo $i
>> ncl plot_aice.ncl fname=$i
>> end
>>
>> I get an error:
>>
>> 700_cice.2011-12-29.nc (from echo $i)
>>
>> Copyright (C) 1995-2011 - All Rights Reserved
>> University Corporation for Atmospheric Research
>> NCAR Command Language Version 6.0.0
>> The use of this software is governed by a License Agreement.
>> See http://www.ncl.ucar.edu/ for more details.
>> fatal:syntax error: line 1 in file /tmp/ncl951.ncl before or near _cice
>> fname=700_cice
>> -------------^
>> fatal:(missing) has no file extension, can't determine type of file to open
>> fatal:Either file (f) isn't defined or variable (aice) is not a variable in the file
>> fatal:Execute: Error occurred at or near line 30 in file plot_aice.ncl
>>
>>
>> I don't think that underscore or dot are special characters that require backslash. Is there a better way to pass the file name on the command line? I see on the NCL website that one can use single quotes, but that will prevent the shell from expanding the variable $i.
>>
>> Thanks for any suggestions!
>> David
>>
>>
>> --
>> David A. Hebert
>> Naval Research Lab
>> Stennis Space Center, MS 39529
>> david.hebert@nrlssc.navy.mil
>> Phone: (228) 688-5846
>> Fax: (228) 688-4759
>> _______________________________________________
>> ncl-talk mailing list
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Fri Feb 3 08:19:57 2012

This archive was generated by hypermail 2.1.8 : Mon Feb 06 2012 - 14:24:56 MST