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

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

对于命令结构-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=8or concatenate,将两个字符串合并为一个,例如s1+ s2。为
赋予意义是一件很奇怪的事情。 terminate the argument+

答案1

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

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

我们只能猜测之所以;选择 ,是因为它也可以在 shell 中终止命令,因此目的类似。但是,出于这个原因,;需要 看到的find必须在 shell 中进行特殊处理,因此\;(';'";"也可以工作)。 不存在这样的问题+

从技术上讲,几乎任何其他字符串都可以用来代替+(与 相同;)。请注意-exec{}+;(在通过转义或引用后通过 shell),可能的测试或操作(如-type-print)都是 的参数find;它们在处理它们时才有意义find,它们的含义取决于它们find的发明方式。

总结一下:

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

更广泛的见解

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

怎么样

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

+手段加法”不是来自上帝的。某人决定之后,其他人纷纷效仿,并将这个符号保留了下来。

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

相关内容