Leo
Leo

Reputation: 1919

How to catch errors or exceptions in Csh?

I would like to know if there is a way to catch the exceptions and control the flow when this happen. For example running this line, I would like to know if a shell error occurred .

source /scripts/scriptThatWillFail.csh

Upvotes: 2

Views: 4337

Answers (1)

Eugeniu Rosca
Eugeniu Rosca

Reputation: 5315

The exit/return code is stored in the status variable in C shell.

source /scripts/scriptThatWillFail.csh
if ($status != 0) then
    echo failed
else
    echo passed
endif

Upvotes: 1

Related Questions