<div dir="ltr"><div>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.</div><div><br></div><div>The only thing that can persist between sub shells is changes to the file system, such as writing temporary files.</div><div><br></div><div>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.</div><div><br></div><div>1.  Go to the target directory before starting the NCL program.</div><div><br></div><div>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 ";".</div><div><br></div><div>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.</div><div><br></div><div>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.</div><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, May 17, 2020 at 11:32 AM M P via ncl-talk <<a href="mailto:ncl-talk@ucar.edu">ncl-talk@ucar.edu</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hello,<div>I have a simple test script that is not doing the right thing.</div><div><div>The output is the same for both first and second system calls</div><div>so that the directory is not changed.</div><div></div></div><div>Can you help with a solution?</div><div>Thanks,</div><div>Mark</div><div><br></div><div>begin<br><br>   ncldir="./test"<br>   command="cd " + ncldir<br><br>   system("pwd")<br>   system(command)<br>   system("pwd")<br><br>end<br><br></div><div>..../mapp/ncl<br>..../mapp/ncl<br></div><div><br></div><div>(same with systemfunc)</div></div></blockquote></div></div>