如何在shell脚本延迟后生成进程?我希望命令在脚本启动后60秒启动,但我想继续运行脚本的其余部分,而不是先等待60秒.这是个主意:
#!/bin/sh
# Echo A 60 seconds later, but without blocking the rest of the script
sleep 60 && echo "A"
echo "B"
echo "C"
Run Code Online (Sandbox Code Playgroud)
输出应该是
B
C
... 60 seconds later
A
Run Code Online (Sandbox Code Playgroud)
我需要能够在一个脚本中完成所有这些操作.IE浏览器.没有创建从第一个shell脚本调用的第二个脚本.
其他答案的轻微扩展是等待脚本结束时的后台命令.
#!/bin/sh
# Echo A 60 seconds later, but without blocking the rest of the script
set -e
sleep 60 && echo "A" &
pid=$!
echo "B"
echo "C"
wait $pid
Run Code Online (Sandbox Code Playgroud)