像 {} 这样的 replstr 是什么?

mbi*_*ras 2 bash xargs string

在文档中xargs提到了该-I标志采用的“replstr”。当我发现要运行以下命令时,我开始阅读有关它的内容fswatch

\n\n
fswatch -0 -e ".*" -i ".rb" . | xargs -0 -n 1 -I {} ruby {}\n
Run Code Online (Sandbox Code Playgroud)\n\n

并开始阅读手册页xargs

\n\n
-I replstr\n        Execute utility for each input line, replacing one or more occurrences of replstr in up to replacements (or 5 if no -R flag is\n        specified) arguments to utility with the entire line of input.  The resulting arguments, after replacement is done, will not be\n        allowed to grow beyond 255 bytes; this is implemented by concatenating as much of the argument containing replstr as possible, to\n        the constructed arguments to utility, up to 255 bytes.  The 255 byte limit does not apply to arguments to utility which do not\n        contain replstr, and furthermore, no replacement will be done on utility itself.  Implies -x. \n
Run Code Online (Sandbox Code Playgroud)\n\n

想想术语“replstr”似乎可能意味着“读取评估打印循环字符串”,这就是它的缩写吗?我开始摆弄它,试图了解正在{}做什么,但我不确定我是否真的明白了:

\n\n
\xe2\x9e\x9c  scripts git:(master) \xe2\x9c\x97  {0..3}\nzsh: command not found: 0..3\n\xe2\x9e\x9c  scripts git:(master) \xe2\x9c\x97 echo {0..3}\n0 1 2 3\n\xe2\x9e\x9c  scripts git:(master) \xe2\x9c\x97 echo {a..3}\na ` _ ^ ] \\ [ Z Y X W V U T S R Q P O N M L K J I H G F E D C B A @ ? > = < ; : 9 8 7 6 5 4 3\n\xe2\x9e\x9c  scripts git:(master) \xe2\x9c\x97 echo {a..d}\na b c d\n\xe2\x9e\x9c  scripts git:(master) \xe2\x9c\x97 echo cats and dogs | xargs\ncats and dogs\n\xe2\x9e\x9c  scripts git:(master) \xe2\x9c\x97 echo cats and dogs | xargs {}\nxargs: {}: No such file or directory\n\xe2\x9e\x9c  scripts git:(master) \xe2\x9c\x97 echo cats and dogs | xargs {} echo {}\nxargs: {}: No such file or directory\n\xe2\x9e\x9c  scripts git:(master) \xe2\x9c\x97 echo cats and dogs | xargs -I {}\n\n\xe2\x9e\x9c  scripts git:(master) \xe2\x9c\x97 echo cats and dogs | xargs -I {} echo {}\ncats and dogs\n
Run Code Online (Sandbox Code Playgroud)\n\n

例如,echo {a..3}对我来说确实没有意义。看起来它确实在做一些事情来达到“替换此处的字符串列表”的效果,但我不确定这是否是正确的看待方式。我也不确定是否{}replstr 是否是特定类型,以及是否有更多类型,或者 replstr 是否只是一对大括号之间的任何内容。希望获得有关 replstr 以及如何处理它们的一些指导。

\n

jll*_*gre 5

replstr意思是“替换字符串”或“替换字符串”。

原来的 replstr 是{}. 它首先是用find命令exec子句引入的,其中它被找到的每个文件名替换,例如

find /tmp -name "foo*" -exec echo file {} found \;
Run Code Online (Sandbox Code Playgroud)

将显示,假设两个文件匹配该模式:

file foo1 found
file foo2 found 
Run Code Online (Sandbox Code Playgroud)

xargs命令允许对从传递到其标准输入的字符串构建的参数执行相同的操作,并且还允许指定与{}替换字符串不同的内容。

请注意,默认的 replstr 只是{}大括号内没有任何内容,后者用于不同的目的,例如您已经注意到的范围或参数扩展。