Moo*_*bie 4 command-line tty xargs kubernetes
我试图执行此命令来修复另一个错误(无法使用 TTY - 输入不是终端或正确类型的文件):
kubectl get pods -n foobar | grep baz | awk '{print $1}' | xargs -J % kubectl exec -it -n foobar % /bin/bash
Run Code Online (Sandbox Code Playgroud)
这导致了以下错误:
xargs: invalid option -- 'o'
Run Code Online (Sandbox Code Playgroud)
我能够在 Mac Mojave 上正确执行该命令,但在 Ubuntu 16.04 上却不能。
根据xargs 网站,应该有一个 -o 选项:
--open-tty
-o
在执行命令之前,在子进程中将 stdin 重新打开为 /dev/tty,从而允许该命令与终端关联,同时 xargs 从不同的流(例如,从管道)读取。如果您希望 xargs 运行交互式应用程序,这很有用。
grep -lz 模式 * | xargs -0o vi
但是man xargs
没有显示这个选项。
该更新日志没有提到任何变化的标志。
我在 Ubuntu 16.04 LTS 上的 xargs 版本:
xargs (GNU findutils) 4.7.0-git
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by Eric B. Decker, James Youngman, and Kevin Dalley.
Run Code Online (Sandbox Code Playgroud)
-o
您要的选项是2017年添加的,您的版本是2016年的,需要升级。
请注意您的版本消息中的年份:
Copyright (C) 2016 Free Software Foundation, Inc.
Run Code Online (Sandbox Code Playgroud)
现在,从findutils
ChangeLog 中查看此部分:
2017-06-08 Bernhard Voelker <mail@bernhard-voelker.de>
xargs: add -o, --open-tty option
This option is available in the xargs implementation of FreeBSD, NetBSD,
OpenBSD and in the Apple variant. Add it for compatibility.
Run Code Online (Sandbox Code Playgroud)
man xargs
来自 2016 版本的示例显示了解决方法:
xargs sh -c 'emacs "$@" < /dev/tty' emacs
Run Code Online (Sandbox Code Playgroud)
此示例emacs
适用于您可能希望运行的任何其他命令,但同样的想法也适用。与-o
选项一样,此方法可确保正在运行的命令可以访问终端。