这是parent.sh:
#!/bin/bash
trap 'exit' SIGHUP SIGINT SIGQUIT SIGTERM
if ! [ -t 0 ]; then # if running non-interactively
sleep 5 & # allow a little time for child to generate some output
set -bm # to be able to trap SIGCHLD
trap 'kill -SIGINT $$' SIGCHLD # when sleep is done, interrupt self automatically - cannot issue interrupt by keystroke since running non-interactively
fi
sudo ~/child.sh
Run Code Online (Sandbox Code Playgroud)
这是child.sh:
#!/bin/bash
test -f out.txt && rm out.txt
for second in {1..10}; do …Run Code Online (Sandbox Code Playgroud)