How to exit calling script in csh?

Tag: exit , csh Author: doristutu Date: 2013-03-15

I have a csh script (a.csh) which calls another (./b.csh). How do I exit from a.csh if some condition is not satisfied while running b.csh?

Here is how I call b.csh

b.csh >&! b.csh.log

There is a related question for bash How to exit all the calling scripts in bash?.

Other Answer1

Inside b.csh, use this to terminate a.csh without terminating b.csh:

set PPID = `ps -ef | awk -v pid="$$" '{if ($2 == pid) {print $3}}'`
kill $PPID

In bash-like shells, $PPID is defined, but for csh we have to extract it manually.

$$ returns the current process ID (pid) (that is, the pid of b.csh).