<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
Hi Bidyut,<br>
<br>
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. 😉<br>
<br>
Because I do not know your NCL script and input file here is a
script which generates dummy files:<br>
<br>
#----------------------------------------<br>
<font face="monospace">#!/bin/bash<br>
<br>
cat << EOF > myfile.txt<br>
Jim<br>
Bob<br>
Ken<br>
EOF<br>
<br>
cat << EOF > myfile.ncl<br>
if(.not. isvar("name")) then <br>
print("Error: missing input 'name'")<br>
else<br>
print(""+name)<br>
end if<br>
EOF<br>
<br>
namelist=$(cat myfile.txt)<br>
<br>
for name in $namelist<br>
do<br>
echo "Input line $i : $name"<br>
<br>
ncl -Q -n name=\""${name}"\" myfile.ncl<br>
<br>
i=$((i+1))<br>
done</font><br>
#----------------------------------------<br>
<br>
Good luck,<br>
Karin<br>
<br>
<div class="moz-cite-prefix">Am 23.04.21 um 05:43 schrieb Bidyut
Bikash Goswami via ncl-talk:<br>
</div>
<blockquote type="cite"
cite="mid:CAOxJJScac3j4uJKRbnfNZOLkc_Ly53=Ubq3fROw281cDusahhQ@mail.gmail.com">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<div dir="ltr">Thank you Brian for your suggestion.
<div><br>
</div>
<div>But the problem still persists even when I try</div>
<div>-------</div>
<div>cat myfile| while read mname <br>
do<br>
ncl myfile.ncl<br>
done<br>
</div>
<div>-------</div>
<div><br>
</div>
<div>I am clueless what can go wrong here.</div>
<div><br>
</div>
<div>Regards,</div>
<div>Bidyut</div>
<div><br>
</div>
</div>
<br>
<div class="gmail_quote">
<div dir="ltr" class="gmail_attr">On Fri, Apr 23, 2021 at 5:15
AM Brian Thomas <<a href="mailto:brian.thomas@washburn.edu"
moz-do-not-send="true">brian.thomas@washburn.edu</a>>
wrote:<br>
</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px
0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div>
<div
style="color:rgb(33,33,33);background-color:rgb(255,255,255)"
dir="auto">
<span
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px;display:inline">Not
certain, but I think your problem is the quotes around
your variable name here:</span></div>
<div
style="color:rgb(33,33,33);background-color:rgb(255,255,255)"
dir="auto">
<span
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px;display:inline">echo
"$mname"</span></div>
<div
style="color:rgb(33,33,33);background-color:rgb(255,255,255)"
dir="auto">
<span
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px;display:inline"><br>
</span></div>
<div
style="color:rgb(33,33,33);background-color:rgb(255,255,255)"
dir="auto">
<span
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px;display:inline">Shouldn't
have " " to make it echo out the contents of $mname</span></div>
<div
style="color:rgb(33,33,33);background-color:rgb(255,255,255)"
dir="auto">
<span
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px;display:inline"><br>
</span></div>
<div
style="color:rgb(33,33,33);background-color:rgb(255,255,255)"
dir="auto">
<span
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px;display:inline">Date:
Thu, 22 Apr 2021 14:26:03 +0900</span><br
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px">
<span
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px;display:inline">From:
Bidyut Bikash Goswami <</span><a
href="mailto:bidyut@yonsei.ac.kr"
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px"
target="_blank" moz-do-not-send="true">bidyut@yonsei.ac.kr</a><span
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px;display:inline">></span><br
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px">
<span
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px;display:inline">To:<span> </span></span><a
href="mailto:ncl-talk@mailman.ucar.edu"
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px"
target="_blank" moz-do-not-send="true">ncl-talk@mailman.ucar.edu</a><br
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px">
<span
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px;display:inline">Subject:
[ncl-talk] Running NCL script from shell script</span><br
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px">
<span
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px;display:inline">Message-ID:</span><br
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px">
<span
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px;display:inline"><</span><a
href="mailto:CAOxJJSdjyHjprWvM-0C8Y20dp1dtEisfiwYzqRdj+OhOts6PqQ@mail.gmail.com"
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px"
target="_blank" moz-do-not-send="true">CAOxJJSdjyHjprWvM-0C8Y20dp1dtEisfiwYzqRdj+OhOts6PqQ@mail.gmail.com</a><span
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px;display:inline">></span><br
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px">
<span
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px;display:inline">Content-Type:
text/plain; charset="utf-8"</span><br
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px">
<br
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px">
<span
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px;display:inline">Hello
All,</span><br
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px">
<br
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px">
<span
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px;display:inline">I
am trying to run my ncl script from the following shell
script:</span><br
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px">
<br
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px">
<span
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px;display:inline">#!/bash/bin</span><br
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px">
<span
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px;display:inline">for
i in {1..2}</span><br
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px">
<span
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px;display:inline">do</span><br
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px">
<span
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px;display:inline">echo
$i</span><br
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px">
<span
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px;display:inline">ncl
myfile.ncl</span><br
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px">
<span
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px;display:inline">done</span><br
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px">
<br
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px">
<span
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px;display:inline">Runs
perfectly fine =></span><br
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px">
<span
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px;display:inline">[</span><a
href="mailto:bidyut@localhost"
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px"
target="_blank" moz-do-not-send="true">bidyut@localhost</a><span
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px;display:inline">]$
sh<span> </span></span><a href="http://test.sh/"
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px"
target="_blank" moz-do-not-send="true">test.sh</a><br
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px">
<span
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px;display:inline">1</span><br
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px">
<span
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px;display:inline">Copyright
(C) 1995-2017 - All Rights Reserved</span><br
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px">
<span
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px;display:inline">University
Corporation for Atmospheric Research</span><br
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px">
<span
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px;display:inline">NCAR
Command Language Version 6.4.0</span><br
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px">
<span
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px;display:inline">The
use of this software is governed by a License Agreement.</span><br
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px">
<span
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px;display:inline">See<span> </span></span><a
href="http://www.ncl.ucar.edu/"
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px;color:rgb(0,120,215)"
target="_blank" moz-do-not-send="true">http://www.ncl.ucar.edu/</a><span
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px;display:inline"><span> </span>for
more details.</span><br
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px">
<span
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px;display:inline">(0)
Hello</span><br
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px">
<span
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px;display:inline">2</span><br
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px">
<span
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px;display:inline">Copyright
(C) 1995-2017 - All Rights Reserved</span><br
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px">
<span
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px;display:inline">University
Corporation for Atmospheric Research</span><br
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px">
<span
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px;display:inline">NCAR
Command Language Version 6.4.0</span><br
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px">
<span
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px;display:inline">The
use of this software is governed by a License Agreement.</span><br
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px">
<span
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px;display:inline">See<span> </span></span><a
href="http://www.ncl.ucar.edu/"
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px;color:rgb(0,120,215)"
target="_blank" moz-do-not-send="true">http://www.ncl.ucar.edu/</a><span
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px;display:inline"><span> </span>for
more details.</span><br
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px">
<span
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px;display:inline">(0)
Hello</span><br
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px">
<br
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px">
<span
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px;display:inline">But
if I try to run:</span><br
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px">
<br
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px">
<span
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px;display:inline">#!/bash/bin</span><br
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px">
<span
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px;display:inline">cat
myfile| while read mname</span><br
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px">
<span
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px;display:inline">do</span><br
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px">
<span
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px;display:inline">echo
"$mname"</span><br
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px">
<span
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px;display:inline">echo
"Running the NCL script"</span><br
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px">
<span
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px;display:inline">ncl
myfile.ncl</span><br
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px">
<span
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px;display:inline">done</span><br
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px">
<br
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px">
<span
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px;display:inline">I
get an error=></span><br
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px">
<span
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px;display:inline">[</span><a
href="mailto:bidyut@localhost"
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px"
target="_blank" moz-do-not-send="true">bidyut@localhost</a><span
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px;display:inline">]$
sh<span> </span></span><a href="http://test1.sh/"
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px"
target="_blank" moz-do-not-send="true">test1.sh</a><br
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px">
<span
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px;display:inline">name1</span><br
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px">
<span
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px;display:inline">Running
the NCL script</span><br
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px">
<span
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px;display:inline">Copyright
(C) 1995-2017 - All Rights Reserved</span><br
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px">
<span
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px;display:inline">University
Corporation for Atmospheric Research</span><br
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px">
<span
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px;display:inline">NCAR
Command Language Version 6.4.0</span><br
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px">
<span
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px;display:inline">The
use of this software is governed by a License Agreement.</span><br
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px">
<span
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px;display:inline">See<span> </span></span><a
href="http://www.ncl.ucar.edu/"
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px;color:rgb(0,120,215)"
target="_blank" moz-do-not-send="true">http://www.ncl.ucar.edu/</a><span
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px;display:inline"><span> </span>for
more details.</span><br
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px">
<span
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px;display:inline">(0)
Hello</span><br
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px">
<span
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px;display:inline">fatal:syntax
error: line -1 before or near \n</span><br
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px">
<span
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px;display:inline">name2</span><br
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px">
<span
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px;display:inline">-----^</span><br
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px">
<br
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px">
<span
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px;display:inline">fatal:error
in statement</span><br
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px">
<br
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px">
<br
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px">
<span
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px;display:inline">What
am I doing wrong?</span><br
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px">
<br
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px">
<span
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px;display:inline">FYI,
Here are the associated file contents:</span><br
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px">
<span
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px;display:inline">[</span><a
href="mailto:bidyut@localhost"
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px"
target="_blank" moz-do-not-send="true">bidyut@localhost</a><span
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px;display:inline">]$
cat myfile</span><br
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px">
<span
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px;display:inline">name1</span><br
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px">
<span
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px;display:inline">name2</span><br
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px">
<br
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px">
<span
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px;display:inline">[</span><a
href="mailto:bidyut@localhost"
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px"
target="_blank" moz-do-not-send="true">bidyut@localhost</a><span
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px;display:inline">]$
cat myfile.ncl</span><br
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px">
<span
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px;display:inline">load
"$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"</span><br
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px">
<span
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px;display:inline">load
"$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"</span><br
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px">
<br
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px">
<span
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px;display:inline">begin</span><br
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px">
<br
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px">
<span
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px;display:inline">print("Hello")</span><br
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px">
<br
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px">
<span
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px;display:inline">end</span><br
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px">
<br
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px">
<span
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px;display:inline">Thanks,</span><br
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px">
<span
style="font-family:-apple-system,HelveticaNeue;font-size:14.6667px;display:inline">Bidyut</span><br>
</div>
<div
id="gmail-m_64638788895627947ms-outlook-mobile-signature">
<div><br>
</div>
Dr. Brian Thomas<br>
Professor<br>
Physics & Astronomy<br>
Washburn University<br>
<br>
Sent from my mobile device</div>
</div>
</blockquote>
</div>
<br clear="all">
<div><br>
</div>
-- <br>
<div dir="ltr" class="gmail_signature">
<div dir="ltr"><i><font face="georgia, serif"><b>Bidyut Bikash
Goswami</b><br>
Research Professor<br>
Irreversible Climate Change Research Center (IRCC)</font></i>
<div>
<div><i><font face="georgia, serif">Yonsei University</font></i></div>
<div><i><font face="georgia, serif">Seoul, South Korea</font></i></div>
</div>
</div>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<pre class="moz-quote-pre" wrap="">_______________________________________________
ncl-talk mailing list
<a class="moz-txt-link-abbreviated" href="mailto:ncl-talk@mailman.ucar.edu">ncl-talk@mailman.ucar.edu</a>
List instructions, subscriber options, unsubscribe:
<a class="moz-txt-link-freetext" href="https://mailman.ucar.edu/mailman/listinfo/ncl-talk">https://mailman.ucar.edu/mailman/listinfo/ncl-talk</a></pre>
</blockquote>
</body>
</html>