加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

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

返回以下错误:
用法:cp [-R [-H | -L | -P]] [-fi | -n] [-apvX] source_file target_file
???????cp [-R [-H | -L | -P]] [-fi | -n] [-apvX] source_file … target_directory

有任何想法吗?

解决方法

如果要使用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                        

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读