[ncl-talk] system/systemfunc commands

Dave Allured - NOAA Affiliate dave.allured at noaa.gov
Sun May 17 12:12:36 MDT 2020


There is an undocumented behavior.  System and systemfunc run their
commands in sub shells.    Your main NCL program runs in the parent shell.
Sub shells can not change the environment of the parent shell.  Therefore,
all environment changes such as the working directory and environment
variables are forgotten at the end of each system command.

The only thing that can persist between sub shells is changes to the file
system, such as writing temporary files.

I have found that when I want to change directories inside an NCL program,
one of these several approaches usually is good enough for what I am trying
to do.

1.  Go to the target directory before starting the NCL program.

2.  Use "cd" inside a system command, but also include all of the other
shell commands within the same system call.  Join different commands
together with semicolon ";".

3.  Use path prefixes on data file names, rather than changing
directories.  You can use either relative or absolute paths, just like in
your normal shell.

One other trap for newcomers is that system and systemfunc commands use
Bourne shell rather than your default shell.  Many commands may work
differently than you expect.  There is a shell select and escape system
that has been too complicated to get my head wrapped around it, so I stick
to the simplest things when using the system command.  HTH.


On Sun, May 17, 2020 at 11:32 AM M P via ncl-talk <ncl-talk at ucar.edu> wrote:

> Hello,
> I have a simple test script that is not doing the right thing.
> The output is the same for both first and second system calls
> so that the directory is not changed.
> Can you help with a solution?
> Thanks,
> Mark
>
> begin
>
>    ncldir="./test"
>    command="cd " + ncldir
>
>    system("pwd")
>    system(command)
>    system("pwd")
>
> end
>
> ..../mapp/ncl
> ..../mapp/ncl
>
> (same with systemfunc)
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20200517/853ce13b/attachment.html>


More information about the ncl-talk mailing list