[ncl-talk] Running NCL script from shell script

Bidyut Bikash Goswami bidyut at yonsei.ac.kr
Wed Apr 21 23:26:03 MDT 2021


Hello All,

I am trying to run my ncl script from the following shell script:

#!/bash/bin
for i in {1..2}
do
echo $i
ncl myfile.ncl
done

Runs perfectly fine =>
[bidyut at localhost]$ sh test.sh
1
 Copyright (C) 1995-2017 - All Rights Reserved
 University Corporation for Atmospheric Research
 NCAR Command Language Version 6.4.0
 The use of this software is governed by a License Agreement.
 See http://www.ncl.ucar.edu/ for more details.
(0) Hello
2
 Copyright (C) 1995-2017 - All Rights Reserved
 University Corporation for Atmospheric Research
 NCAR Command Language Version 6.4.0
 The use of this software is governed by a License Agreement.
 See http://www.ncl.ucar.edu/ for more details.
(0) Hello

But if I try to run:

#!/bash/bin
cat myfile| while read mname
do
echo "$mname"
echo "Running the NCL script"
ncl myfile.ncl
done

I get an error=>
[bidyut at localhost]$ sh test1.sh
name1
Running the NCL script
 Copyright (C) 1995-2017 - All Rights Reserved
 University Corporation for Atmospheric Research
 NCAR Command Language Version 6.4.0
 The use of this software is governed by a License Agreement.
 See http://www.ncl.ucar.edu/ for more details.
(0) Hello
fatal:syntax error: line -1 before or near \n
name2
-----^

fatal:error in statement


What am I doing wrong?

FYI, Here are the associated file contents:
[bidyut at localhost]$ cat myfile
name1
name2

[bidyut at localhost]$ cat myfile.ncl
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"

begin

print("Hello")

end

Thanks,
Bidyut
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20210422/27fd358b/attachment.html>


More information about the ncl-talk mailing list