0

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?.

Community
  • 1
  • 1
user13107
  • 3,239
  • 4
  • 34
  • 54

1 Answers1

0

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).

supergra
  • 1,578
  • 13
  • 19