在bash`-exec命令{} +`中+是什么意思?

刮y的

对于命令结构-exec command {} \;,我输入了信息man find

  1. {}表示selected files
  2. ; 意味着中止论点。
  3. \; 逃脱以保护它们免遭外壳膨胀。

在有关的段落中-exec command {} +

 -exec command {} +
              This  variant  of the -exec action runs the specified command on
              the selected files, but the command line is built  by  appending
              each  selected file name at the end; the total number of invoca‐
              tions of the command will  be  much  less  than  the  number  of
              matched  files.   The command line is built in much the same way
              that xargs builds its command lines.  Only one instance of  `{}'
              is  allowed  within the command, and (when find is being invoked
              from a shell) it should be quoted (for example, '{}') to protect
              it  from  interpretation  by shells.  The command is executed in
              the starting directory.  If any invocation  returns  a  non-zero
              value  as exit status, then find returns a non-zero exit status.
              If find encounters an error, this can sometimes cause an immedi‐
              ate  exit, so some pending commands may not be run at all.  This
              variant of -exec always returns true.

它从不说什么+,bash +是什么意思-exec command {} +
它的意思是终止诸如;?之类的参数
+表示加号(例如3+5=8或)concatenate,将两个字符串合并为一个字符串(例如s1+)s2
这是指定的意思一件奇怪的事情terminate the argument+

卡米尔·马乔洛夫斯基(Kamil Maciorowski)

它与Bash无关,它是find语法的一部分该命令必须知道操作在哪里-exec结束。它在;或处结束+根据终止字符,使用适当的-exec动作变体

为什么要为此目的选择这两个字符?我不知道。一些方式来结束-exec声明是必须的,有人选择了;+现在,当涉及到find命令时,这些字符已成为POSIX标准的一部分

我们只能猜测;是选择它的原因,因为它也可以在shell中终止命令,因此目的是相似的。出于这个原因,然而,;需要由被视为find必须在外壳经过特殊处理的,因此\;';'或者";"也适用)。不会有这样的问题+

从技术上讲,几乎可以选择其他任何字符串来代替+(与相同;)。需要注意的是-exec{}+;(后通过壳感谢逃逸或引用),可能测试或类似的行动-type-print-他们都是参数find; 它们在find处理它们时变得有意义,它们的含义来自find发明的方式。

总结一下:

  1. 这是关于find,而不是关于bash
  2. 该工具支持两个略有不同的-exec操作。
  3. 为了区分它们,我们使用了两个不同的终止-exec语句参数这是一种设计选择。
  4. 这两个不同的论点是;+; 这是一种设计选择。
  5. 这些选择本来可以有所不同。即使背后有一个故事+(我不知道),这也是琐事,并不是真正有意义的事情。我只能推测{} +是“一个或多个参数”,例如10+有时表示“十个或多个”。

更广泛的见识

+表示加号(例如3+5=8或)concatenate,将两个字符串合并为一个字符串(例如s1+)s2赋予含义终止参数是一件很奇怪的事情+

怎么样

>的意思是“大于”…为赋予一个“重定向”的含义是一件很奇怪的事情>

+意味着加”不是来自上帝。有人决定,其他人紧随其后,标志被粘住了。

  • 有人认为+数学的意思是“加”。
  • 有人认为>数学中的意思是“大于”。
  • 有人决定>在shell中进行重定向。
  • 有人决定上下文中+终止-execfind

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章