I have this sample perl code, where $a $b $c values can be changed and has exit code $ex. I call this from another shell script, which is affected by abc.pl’s exit code. How do I capture just the exit code of this perl.
my $a=0; my $b=0; my $c=0;
my $sum = $a+$b+$c; $ex = 0;
if($sum == 0){
print "success"; print " $ex \n";
}else{
$ec=1 ; print "Not success"; print " $ex \n";
}
exit $ex;
Sample shell script.
echo start
set ecd = `abc.pl`
echo $ecd
echo stop
Here $ecd prints whatever is the output of abc.pl, but not just the exit code.
>Solution :
$? contains the exit code of the last executed command.
set ecd = `abc.pl`
set status = $?