本文介绍了如何在bash杀害后要喝preSS终止的消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你怎么能燮preSS你杀死一个之后出现的终止信息
在bash脚本程序?

How can you suppress the Terminated message that comes up after you kill aprocess in a bash script?

我试过套装+ BM ,但不起作用。

我知道另一种解决方案需要调用 EXEC 2 - ;的/ dev / null的,而且是
可靠?我如何重置回来,这样我可以继续看到标准错误?

I know another solution involves calling exec 2> /dev/null, but is thatreliable? How do I reset it back so that I can continue to see stderr?

推荐答案

简短的回答是,你不能。巴什始终打印前台作业的状态。监测标记仅适用于后台作业,只有在交互shell,而不是脚本。

The short answer is that you can't. Bash always prints the status of foreground jobs. The monitoring flag only applies for background jobs, and only for interactive shells, not scripts.

看到jobs.c notify_of_job_status()。

see notify_of_job_status() in jobs.c.

就像你说的,你可以这样重定向标准错误指向到/ dev / null的但你错过任何其他错误消息。你可以把它暂时做在运行脚本子shell的重定向。这使得原来的环境中独自一人。

As you say, you can redirect so standard error is pointing to /dev/null but then you miss any other error messages. You can make it temporary by doing the redirection in a subshell which runs the script. This leaves the original environment alone.

(script 2> /dev/null)

这将失去所有的错误信息,而只是从脚本,而不是在外壳别的运行。

which will lose all error messages, but just from that script, not from anything else run in that shell.

您可以保存和恢复标准错误,通过重定向一个新的文件描述符来点有:

You can save and restore standard error, by redirecting a new filedescriptor to point there:

exec 3>&2          # 3 is now a copy of 2
exec 2> /dev/null  # 2 now points to /dev/null
script             # run script with redirected stderr
exec 2>&3          # restore stderr to saved
exec 3>&-          # close saved version

不过,我不会推荐这一点 - 从第一个唯一的好处是,它节省了子shell调用,同时更加复杂和,甚至可能改变脚本的行为,如果脚本改变文件描述符

But I wouldn't recommend this -- the only upside from the first one is that it saves a sub-shell invocation, while being more complicated and, possibly even altering the behavior of the script, if the script alters file descriptors.

这篇关于如何在bash杀害后要喝preSS终止的消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 14:48