首页 > 解决方案 > bash 本身生成的静音错误

问题描述

我需要有一个安排,其中有时bash -ic在没有 pty 的情况下执行。我必须使用 -i(需要运行 .bashrc)并且我必须没有 pty(通过 ssh 传输标准输入)。但是,我不想看到这个:

bash: cannot set terminal process group (20605): Inappropriate ioctl for device
bash: no job control in this shell

我只能用 过滤掉它2> >(grep -v 'bash: '),但我更愿意屏蔽 bash 本身,因为该过滤器也适用于该 bash 运行的任何命令 (-c)。

重申一下,我正在寻找一种方法来消除与 bash 本身相关的警告 - 而不是它执行的脚本。

如果你想重现它,试试这个:

$ echo hello |ssh -t you@<linuxHost> bash -ic cat -
bash: cannot set terminal process group (-1): Inappropriate ioctl for device
bash: no job control in this shell
hello

标签: linuxbashssh

解决方案


使用ssh -tt.

引用ssh手册

-t强制伪终端分配。这可用于在远程机器上执行任意基于屏幕的程序,这非常有用,例如在实现菜单服务时。多个-t 选项强制 tty 分配,即使 ssh 没有本地 tty。


推荐阅读