Re: command line variable string

From: David Brown <dbrown_at_nyahnyahspammersnyahnyah>
Date: Fri Feb 03 2012 - 07:29:36 MST

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 07:29:53 2012

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