How can you suppress the the output resulting from kill
when the target process is a parent of the current one?
I'm using the following function to exit out of any level of nested shells but keep the last one open:
function surface(){
if [ $SHLVL -gt 1 ]; then
target=$(pstree -p $$ | grep -m 2 sh$ | tail -1 | awk '{print $2}') &>/dev/null
kill -1 $target &>/dev/null
fi
}
But this still prints the message Hangup: 1
to the terminal.
Adding wait $target
after kill
fails, as wait
gives the error: bash: wait: pid 1234 is not a child of this shell
.
I also tried using disown
, but that similarly fails because the target process is a parent of the current one.
Related: