小编S K*_*Kos的帖子

当父以交互方式/通过终端调用父进程时,bash子脚本与父脚本一起退出,但在非交互式/通过cron调用时则不会

这是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)

linux bash shell

8
推荐指数
1
解决办法
908
查看次数

标签 统计

bash ×1

linux ×1

shell ×1