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?

情到浓时终转凉″ 提交于 2021-01-27 18:23:12

问题


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:

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.

Note: I have tried set -m in .bashrc, but bash still writes out the warnings on start up - the ~/.bashrc file might be executed after the shell tries to assert job control. Is there a command line option which would work?


回答1:


man bash says about set options that The options can also be specified as arguments to an invocation of the shell. Note you will need +m not -m. Admittedly the manual isn't quite clear on that.

However looking at bash source code (version 4.2), apparently it ignores the state of this flag. I would say this is a bug.

Applying the following small patch makes bash honor the m flag on startup. Unfortunately this means you will have to recompile 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 +m now, though.

$ ./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


来源:https://stackoverflow.com/questions/13300764/how-to-tell-bash-not-to-issue-warnings-cannot-set-terminal-process-group-and

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!