如何在后台运行命令而没有输出? [英] How to run a command in the background and get no output?

查看:73
本文介绍了如何在后台运行命令而没有输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

stdoutstderr 重定向到 /dev/null 以忽略输出.

Redirect the stdout and stderr to /dev/null to ignore the output.

nohup /path/to/your/script.sh > /dev/null 2>&1 &

这篇关于如何在后台运行命令而没有输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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