如何在后台运行shell脚本并且不输出任何信息 [英] How to run a shell script in the background and get no output

查看:1313
本文介绍了如何在后台运行shell脚本并且不输出任何信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了两个shell脚本a.shb.sh.在a.shb.sh中,我有一个无限的for循环,它们将一些输出输出到终端.我想编写另一个同时调用a.shb.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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆