当无法断言作业控制时,如何告诉 bash 不要发出警告“无法设置终端进程组”和“此外壳中没有作业控制”?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 
原文地址: http://stackoverflow.com/questions/13300764/
Warning: these are provided under cc-by-sa 4.0 license.  You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to tell bash not to issue warnings "cannot set terminal process group" and "no job control in this shell" when it can't assert job control?
提问by halloleo
To create a new interactive bash shell I call bash -i. Due to issues with my environment, bash cannot assert job control (I'm using cygwin bash in GNU emacs) and issues warnings ("cannot set terminal process group" and "no job control in this shell"). - I have to live with the disabled job control in my environment, but I would like to get rid of the warning:
要创建一个新的交互式 bash shell,我调用bash -i. 由于我的环境问题,bash 无法断言作业控制(我在 GNU emacs 中使用 cygwin bash)并发出警告(“无法设置终端进程组”和“此 shell 中没有作业控制”)。- 我必须在我的环境中忍受禁用的作业控制,但我想摆脱警告:
How can I tell bash not to assert job control and not to issue these warnings? I obviously still want the shell as an interactive one.
如何告诉 bash 不要断言作业控制并且不要发出这些警告?我显然仍然希望 shell 作为交互式 shell。
Note: I have tried set -min .bashrc, but bash still writes out the warnings on start up - the ~/.bashrcfile might be executed afterthe shell tries to assert job control. Is there a command line option which would work?
注意:我已经尝试set -m过.bashrc,但是 bash 仍然会在启动时写出警告 - 该~/.bashrc文件可能会在shell 尝试断言作业控制后执行。有没有可以工作的命令行选项?
回答by Jester
man bashsays about setoptions that The options can also be specified as arguments to an invocation of the shell.Note you will need +mnot -m. Admittedly the manual isn't quite clear on that.
man bash说到set选项选项也可以指定为调用 shell 的参数。请注意,您将需要+m不-m。诚然,手册对此并不十分清楚。
However looking at bashsource code (version 4.2), apparently it ignores the state of this flag. I would say this is a bug.
但是查看bash源代码(版本 4.2),显然它忽略了这个标志的状态。我会说这是一个错误。
Applying the following small patch makes bashhonor the mflag on startup. Unfortunately this means you will have to recompile bash.
应用以下小补丁可以在启动时bash兑现m标志。不幸的是,这意味着您将不得不重新编译bash.
--- jobs.c.orig 2011-01-07 16:59:29.000000000 +0100
+++ jobs.c      2012-11-09 03:34:49.682918771 +0100
@@ -3611,7 +3611,7 @@
     }
   /* We can only have job control if we are interactive. */
-  if (interactive == 0)
+  if (interactive == 0 || !job_control)
     {
       job_control = 0;
       original_pgrp = NO_PID;
Tested on my linux machine where job control is available by default, so the error messages you see on mingw are not printed here. You can still see that bash honors the +mnow, though.
在我的 linux 机器上进行了测试,默认情况下可以使用作业控制,因此您在 mingw 上看到的错误消息不会在此处打印。不过,您仍然可以看到 bash 尊重+m现在。
$ ./bash --noprofile --norc
$ echo $-
himBH
$ fg
bash: fg: current: no such job
$ exit
$ ./bash --noprofile --norc +m
$ echo $-
hiBH
$ fg
bash: fg: no job control

