I have a Bash parent script that on unexpected input calls an error logging child script that logs the error. I also want the execution to halt when the error occurs and the error script is called. But if I call exit
from the error handling script it does not stop the parent script from executing. How may I go about stopping a parent script from a child?
相关问题
- JQ: Select when attribute value exists in a bash a
- bash print whole line after splitting line with if
- “command not found” errors in expect script execut
- grep using grep results
- UNIX Bash - Removing double quotes from specific s
相关文章
- Check if directory exists on remote machine with s
- Reverse four length of letters with sed in unix
- Launch interactive SSH bash session from PHP
- BASH: Basic if then and variable assignment
- Bash script that creates a directory structure
- Test if File/Dir exists over SSH/Sudo in Python/Ba
- How can I create a “tmp” directory with Elastic Be
- Spread 'sed' command over multiple lines
Extension to @anishsane comment because MacOS has little bit different
ps
syntax.Finding parent process ID (ppid) in child script under Mac OS (Darwin):
kill -SIGUSR1 $(ps $$ -o ppid=);exit
Try:
In parent script:
In child script:
Other way was:
In child script:
But, it is not recommended, because the parent needs to have some information about getting killed & thus do some cleanup if required.
Another way: Instead of calling the child script,
exec
it.However, as pointed out in other answer, the cleanest way is to exit from parent, after the child returns.
try..
so,
You don't want
stop the parent from a child
(the parents usually don't like this behavior) :), you instead wanttell to parent - need stop
and he will stop itself (if want) ;)Don't try to terminate the parent from the child. Instead call
exit
in the parent after the child script returned.or shorter