【问题标题】: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?当bash无法断言作业控制时,如何告诉bash不要发出警告“无法设置终端进程组”和“在这个shell中没有作业控制”?
【发布时间】:2012-11-09 01:19:24
【问题描述】:

要创建一个新的交互式 bash shell,我调用 bash -i。由于我的环境问题,bash 无法断言作业控制(我在 GNU emacs 中使用 cygwin bash)并发出警告(“无法设置终端进程组”和“此 shell 中没有作业控制”)。 - 我必须在我的环境中使用禁用的作业控制,但我想摆脱警告:

如何告诉 bash 不要断言作业控制并且不要发出这些警告?我显然仍然希望 shell 作为交互式的。

注意:我在.bashrc 中尝试过set -m,但 bash 仍然会在启动时写出警告 - ~/.bashrc 文件可能会在 shell 尝试断言作业控制之后执行 .是否有一个命令行选项可以工作?

【问题讨论】:

    标签: bash command-line .bash-profile job-control


    【解决方案1】:

    man bash 提到了set 选项,这些选项也可以指定为调用 shell 的参数。 请注意,您需要 +m 而不是 -m。诚然,手册对此并不十分清楚。

    但是查看bash 源代码(4.2 版),显然它忽略了这个标志的状态。我会说这是一个错误。

    应用以下小补丁使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;
    

    在我的 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
    

    【讨论】:

    • 关注@Jester!感谢这个经过充分研究且始终如一的书面答案。 - 它甚至完全适合我! ;-)
    • 顺便说一句,你提交了错误吗?如果没有,我很乐意这样做。
    猜你喜欢
    • 2012-08-03
    • 1970-01-01
    • 1970-01-01
    • 2011-11-04
    • 1970-01-01
    • 2016-11-04
    • 1970-01-01
    • 2011-04-21
    • 1970-01-01
    相关资源
    最近更新 更多