shell – 从标准输出管道传输中使用两次参数
发布时间:2020-12-15 22:46:32 所属栏目:安全 来源:网络整理
导读:我有一个命令行工具,它接收两个参数: TOOL arg1 -o arg2 我想用arg1和arg2提供的相同参数调用它,为了让我这么容易,我想我会这样做: each arg1_value | TOOL $1 -o $1 但这不起作用,$1不会被替换,但会在命令行末尾添加一次. 一个明确的例子,执行: cp fileA
我有一个命令行工具,它接收两个参数:
TOOL arg1 -o arg2 我想用arg1和arg2提供的相同参数调用它,为了让我这么容易,我想我会这样做: each <arg1_value> | TOOL $1 -o $1 但这不起作用,$1不会被替换,但会在命令行末尾添加一次. 一个明确的例子,执行: cp fileA fileA 返回错误fileA和fileA相同(未复制) echo fileA | cp $1 $1 返回以下错误: 有任何想法吗? 解决方法
如果要使用xargs,[ – I]选项可能会有所帮助:
-I replace-str Replace occurrences of replace-str in the initial-arguments with names read from standard input. Also,unquoted blanks do not terminate input items; instead the separa |