[ncl-talk] determine success of ncl script via bash

Dave Allured - NOAA Affiliate dave.allured at noaa.gov
Thu Nov 12 11:32:45 MST 2020


The NCL function *status_exit* allows the user program to set the integer
exit status code, which can be read by the shell.  This is probably what
you want.  See the example and discussion on that function's doc page.

I can think of four kinds of NCL fatal errors:

* NCL reports a "fatal error" to the console, but the program keeps running
and does not exit.  This happens more often than I would like.
* NCL internally detects some kind of fatal error, and exits to the shell.
* NCL has an uncontrolled crash and exits to the shell.
* An NCL user program detects a problem and exits to the shell using the
*status_exit* function.

Unfortunately the exit status code is undefined in the first three cases.
This is why it is best for user programs to manually check for predictable
errors, and handle their own error exits in an intelligent way.  One
example is to check for missing input files with functions like
*isfilepresent* before blindly trying to open them with *addfile*,
*cbinread*, etc.

Also I usually use an *if* statement in C shell to check the exit code.
Not being a bash expert, I do not understand the double pipe syntax in your
example.  If you think your NCL program is emitting proper exit codes, you
might check your bash code to make sure it is doing what you think.


On Thu, Nov 12, 2020 at 10:57 AM Micah Sklut via ncl-talk <
ncl-talk at mailman.ucar.edu> wrote:

> Hi,
>
> I run a bunch of ncl script operationally in bash scripts. I'd like to be
> able to detect if NCL encounters a fatal error. Any suggestions on this?
>
> I've tried this without success:
>
> ncl nam_file.ncl || {
>     echo 'failure'
>     exit
>   }
>
> Thanks.
> --
> Micah Sklut
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20201112/7342708f/attachment.html>


More information about the ncl-talk mailing list