问题描述
我已经开始在linux终端中组合不同的命令了.我想知道为什么以下命令需要反斜杠和分号:
I have begun to combine different commands in the linux terminal. I am wondering why the backslash and semicolon are required for a command such as:
find ./ -name 'blabla' -exec cp {} ./test ;
当一个简单的 cp 命令很简单时:
when a simple cp command is simply:
cp randomfile ./test
没有 ;
它们是要清楚地指示命令的结束,还是只是在文档中要求?基本原理是什么?
Are they to clearly indicate the end of a command, or is it simply required in the documentation? What is the underlying principle?
推荐答案
使用分号前的反斜杠,因为;
是列表运算符之一(或&&
, ||
) 用于分隔 shell 命令.例如:
The backslash before the semicolon is used, because ;
is one of list operators (or &&
, ||
) for separating shell commands. In example:
command1; command2
find
实用程序正在使用 ;
或 +
来终止由 -exec
调用的 shell 命令.
The find
utility is using ;
or +
to terminate the shell commands invoked by -exec
.
因此,为了避免特殊的 shell 字符被解释,它们需要用反斜杠转义,以删除下一个字符读取和行继续的任何特殊含义.
So to avoid special shell characters from interpretation, they need to be escaped with a backslash to remove any special meaning for the next character read and for line continuation.
因此,find
命令允许使用以下示例语法:
Therefore the following example syntax is allowed for find
command:
find . -exec echo {} ;
find . -exec echo {} ';'
find . -exec echo {} ";"
find . -exec echo {} +
find . -exec echo {} +
另见:
这篇关于为什么 find 命令的 -exec 选项需要反斜杠和分号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!