会话中启动shell脚本,然后让脚本一直以后台模式运行到结束,即使你退 出了终端会话。这可以用nohup命令来实现。
code
macname@MacdeMacBook-Pro Desktop % cat test.sh #!/bin/bash # Trapping the script exit # trap "echo Goodbye..." EXIT # count=1 while [ $count -le 5 ] do echo "Loop #$count" sleep 1 count=$[ $count + 1 ] done% macname@MacdeMacBook-Pro Desktop % macname@MacdeMacBook-Pro Desktop % macname@MacdeMacBook-Pro Desktop % nohup ./test.sh & [1] 43365 macname@MacdeMacBook-Pro Desktop % appending output to nohup.out [1] + done nohup ./test.sh macname@MacdeMacBook-Pro Desktop % cat nohup.out Loop #1 Loop #2 Loop #3 Loop #4 Loop #5 Goodbye... macname@MacdeMacBook-Pro Desktop %