[ncl-talk] Bash variables not being read via system() function

Tabish Ansari tabishumaransari at gmail.com
Sat Oct 8 06:34:27 MDT 2022


Hello,

I have a small shell script *myscript.sh* which takes 13 arguments: start
day, and 12 values of emission levels. For now, it just echoes them back on
the screen.

I'm supplying these 13 numbers via an NCL script by writing them out to a
text file and reading them again in the shell. NCL is nicely writing these
text files out and myscript.sh is able to pick these arguments when I write
the command in bash. However, when I try to achieve the same from inside
NCL using the system() function, the shell script isn't able to read these
arguments.

Here's *myscript.sh:*
#!/bin/bash
echo day=$1
echo Ai=$2
echo Ap=$3
echo At=$4
echo Ar=$5
echo Bi=$6
echo Bp=$7
echo Bt=$8
echo Br=$9
echo Ci=${10}
echo Cp=${11}
echo Ct=${12}
echo Cr=${13}

And here's my NCL script:
begin

SD = 02 ; start day
baseline = (/100,100,100,100,100,100,100,100,100,100,100,100/)

emis = baseline
print("PREPARING EMISSIONS: "+emis(0)+" "+emis(1)+" "+emis(2)+" "+emis(3)+"
"+emis(4)+" "+emis(5)+" "+emis(6)+" "+emis(7)+" "+emis(8)+" "+emis(9)+"
"+emis(10)+" "+emis(11))

asciiwrite("emisstring.txt",emis)
asciiwrite("SD.txt",SD)

system("./myscript.sh $(<SD.txt) $(<emisstring.txt)")

end

These two scripts are self-sufficient and you can easily copy-paste and
test them on your system. Please let me know what's wrong here.

Thanks a lot.

Tabish
-------------------------------
Dr Tabish Ansari
Research Associate
Air Quality Modelling Group
IASS-Potsdam
Germany
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20221008/2afa7305/attachment.htm>


More information about the ncl-talk mailing list