如何在后台运行shell脚本并且不输出任何信息 [英] How to run a shell script in the background and get no output
问题描述
我写了两个shell脚本a.sh
和b.sh
.在a.sh
和b.sh
中,我有一个无限的for循环,它们将一些输出输出到终端.我想编写另一个同时调用a.sh
和b.sh
的脚本,但我希望用户立即重新获得对终端的控制权,而不是让脚本无限运行并希望将输出隐藏在终端中.
I wrote two shell scripts a.sh
and b.sh
. In a.sh
and b.sh
I have a infinite for loop and they print some output to the terminal. I want to write another script which calls both a.sh
and b.sh
but I want the user to regain control of the terminal immediately, instead of having the script run infinitely and I want to hide the output in terminal.
推荐答案
如果您的后台作业需要很长时间才能完成,或者您仅使用SecureCRT或类似的东西登录服务器,请使用nohup
.
Use nohup
if your background job takes a long time to finish or you just use SecureCRT or something like it login the server.
将 stdout 和 stderr 重定向到/dev/null
以忽略输出.
Redirect the stdout and stderr to /dev/null
to ignore the output.
nohup /path/to/your/script.sh > /dev/null 2>&1 &
这篇关于如何在后台运行shell脚本并且不输出任何信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!