Bulrush Bulrush - 29 days ago 14
Linux Question

How to check status of error code in csh?

This is not a Perl questions, this is a csh question.

Perl 5.8.8 on Linux RHEL 5.5.56.

I have a test Perl program which uses 'exit 3;' to set the exit status. The Perl program is run from a csh script I call 'test'.

Perl program:

#/usr/bin/perl
# July 11, 2014
# Test exit code with csh $status variable
my($i);
$i=3;
print "$0 Exit with error code $i\n";
exit $i;


'test' csh script that calls Perl progam:

#/bin/csh
# July 10, 2014,

perl tstatus.pl
echo "Status=$status"
if ($status > 0) then
echo "ERROR in status: $status"
endif


The line 'echo "ERROR in status: $status" is never executed even though 'echo "Status=$status' says status is 3.

How do I get my csh to check and act on the value of $status?
$status is a system variable it seems.

I have also tried 'if ($stats) then' but that doesn't work either. No errors are reported in the csh script.

Thank you.

p.s. I don't do complicated stuff in csh so I'm not ready to go to bash yet. I've read the "why not csh" file already. Thanks.

Answer

The echo command succeeds, resetting $status to 0. Thus if never sees nonzero $status.

Therefore the solution is to either eliminate the echo command or save the value of $status immediately after the perl command.

I recently encountered a similar issue myself.