[ncl-talk] Running NCL script from shell script
Lyndz
olagueralyndonmark429 at gmail.com
Fri Apr 23 05:24:41 MDT 2021
Hi,
Here's another approach.
#!/bin/bash
input="myfile.txt"
while IFS= read -r mname
do
echo "$mname"
echo "Running the NCL script"
ncl myfile.ncl
done < $input
You need to add exit in the ncl script (myfile.ncl)
begin
print ("Hello")
end
exit
See attached files.
Lyndz
On Fri, Apr 23, 2021 at 6:50 PM Karin Meier-Fleischer via ncl-talk <
ncl-talk at mailman.ucar.edu> wrote:
> Hi Bidyut,
>
> the problem is the use of the double quotes. And it would be a better way
> to read the myfile content into an array and use a for loop instaed of
> 'while read', but that is how I would do it. 😉
>
> Because I do not know your NCL script and input file here is a script
> which generates dummy files:
>
> #----------------------------------------
> #!/bin/bash
>
> cat << EOF > myfile.txt
> Jim
> Bob
> Ken
> EOF
>
> cat << EOF > myfile.ncl
> if(.not. isvar("name")) then
> print("Error: missing input 'name'")
> else
> print(""+name)
> end if
> EOF
>
> namelist=$(cat myfile.txt)
>
> for name in $namelist
> do
> echo "Input line $i : $name"
>
> ncl -Q -n name=\""${name}"\" myfile.ncl
>
> i=$((i+1))
> done
> #----------------------------------------
>
> Good luck,
> Karin
>
> Am 23.04.21 um 05:43 schrieb Bidyut Bikash Goswami via ncl-talk:
>
> Thank you Brian for your suggestion.
>
> But the problem still persists even when I try
> -------
> cat myfile| while read mname
> do
> ncl myfile.ncl
> done
> -------
>
> I am clueless what can go wrong here.
>
> Regards,
> Bidyut
>
>
> On Fri, Apr 23, 2021 at 5:15 AM Brian Thomas <brian.thomas at washburn.edu>
> wrote:
>
>> Not certain, but I think your problem is the quotes around your variable
>> name here:
>> echo "$mname"
>>
>> Shouldn't have " " to make it echo out the contents of $mname
>>
>> Date: Thu, 22 Apr 2021 14:26:03 +0900
>> From: Bidyut Bikash Goswami <bidyut at yonsei.ac.kr>
>> To: ncl-talk at mailman.ucar.edu
>> Subject: [ncl-talk] Running NCL script from shell script
>> Message-ID:
>> <CAOxJJSdjyHjprWvM-0C8Y20dp1dtEisfiwYzqRdj+OhOts6PqQ at mail.gmail.com>
>> Content-Type: text/plain; charset="utf-8"
>>
>> 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
>>
>> Dr. Brian Thomas
>> Professor
>> Physics & Astronomy
>> Washburn University
>>
>> Sent from my mobile device
>>
>
>
> --
>
>
> *Bidyut Bikash Goswami Research Professor Irreversible Climate Change
> Research Center (IRCC)*
> *Yonsei University*
> *Seoul, South Korea*
>
> _______________________________________________
> ncl-talk mailing listncl-talk at mailman.ucar.edu
> List instructions, subscriber options, unsubscribe:https://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at mailman.ucar.edu
> List instructions, subscriber options, unsubscribe:
> https://mailman.ucar.edu/mailman/listinfo/ncl-talk
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20210423/a560e519/attachment.html>
-------------- next part --------------
name1
name2
name3
-------------- next part --------------
A non-text attachment was scrubbed...
Name: read.sh
Type: text/x-sh
Size: 135 bytes
Desc: not available
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20210423/a560e519/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: myfile.ncl
Type: application/octet-stream
Size: 31 bytes
Desc: not available
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20210423/a560e519/attachment.obj>
More information about the ncl-talk
mailing list