我试图执行这个命令来修复另一个错误(无法使用TTY -输入不是终端或正确的文件):
kubectl get pods -n foobar | grep baz | awk '{print $1}' | xargs -J % kubectl exec -it -n foobar % /bin/bash导致以下错误:
xargs: invalid option -- 'o'我能够在我的Mojave上正确地执行命令,但在Ubuntu16.04上没有正确执行。
根据xargs网站,应该有一个-o选项:
--在执行命令之前,打开-tty -o在子进程中重新打开stdin作为/dev/tty,从而允许该命令在xargs从另一个流(例如从管道)读取时与终端相关联。如果您希望xargs运行交互式应用程序,这是非常有用的。grep -lz模式* xargs -0o vi
但是man xargs没有显示这个选项。
变化量g没有提到对国旗的任何更改。
我在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.发布于 2019-07-15 06:20:16
您想要的-o选项是在2017年添加的。你的版本是2016年开始的。你需要升级。
请注意版本消息中的年份:
Copyright (C) 2016 Free Software Foundation, Inc.现在,查看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.2016年版本的man xargs给出了一个解决方案的示例:
xargs sh -c 'emacs "$@" < /dev/tty' emacs这个示例适用于emacs,但同样的想法也适用于您希望运行的任何其他命令。与-o选项一样,这种方法确保正在运行的命令能够访问终端。
https://askubuntu.com/questions/1158334
复制相似问题