为什么这个shell命令出错 [英] why this shell command wrong
本文介绍了为什么这个shell命令出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
find -name "*.c" -exec ls -l {} /;
它说缺少"-exec"的参数,
为什么呢〜?
请也告诉我最后的"/"是什么,谢谢
it says missing argument to ''-exec'',
why is that~?
Please tell me what is ''/'' at the end means as well, thanks
推荐答案
正确的行是:
The correct line would be:
find -name "*.c" -exec ls -l \{\} \;
或
or
find -name "*.c" -exec ls -l ''{}'' '';''
或
or
find -name "*.c" -exec ls -l ''{}'' \;
...
您看到图案了吗?
推理吗?
...
You see the pattern?
Reasoning?
- shell将命令行分为多个块(第一个块是命令,其余的是命令的各个参数)
- 由于壳本身是一种语言,因此它具有一些相关的标点符号和运算符-除其他外,{}和;对shell具有意义
- ,因为find命令还需要进行{}和;的某些操作.作为自变量,必须确保{}和;不由外壳程序解释,而是传递给find命令.有两种方法可以实现:转义或放置到文字字符串中.
- 转义是在一个字符前放置一个\-然后,该字符不被外壳解释并按原样传递(不加引号). \)
- ''...''字符串在除去开头和结尾的单引号后按原样传递
- "..."字符串由shell评估进行变量替换和其他功能,然后才能使用(通过删除引号)
- the shell splits the command line into chunks (1st chunk is the command, the rest are the individual arguments to the command)
- since the shell is a language in it self, it has some relevant punctuation and operator symbols - among others, { } and ; have a meaning to the shell
- since the find command also needs for some operations the {} and ; as own arguments, one must make sure that the {} and the ; are not interpreted by the shell, but are rather passed to the find command. There are two possibilities to achieve that: escaping or placing into a literal string.
- escaping is placing a \ before one character - the character then is not interpreted by the shell and is passed as-is (without leading \)
- ''...'' strings are passed as-is, after stripping off the leading and trailing single quote
- "..." strings get evaluated by the shell for variable substitution and other functions and only then are taken (by stripping off the quotes)
注意:如果希望将文本原样传递给命令,请使用单引号字符串(''...'').如果要放置{}或;到"{}"";;"中,它们由外壳程序解释,因此可能不会原样传递给find命令.
Note: If you want a text be passed unchanged to a command, use single quoted string (''...''). If you would place the {} or the ; into "{}" ";", they are interpreted by the shell and thus might not be passed unchanged to the find command.
您需要使用反斜杠来转义分号.这样的字符:
You need to use the backslash to escape the semi-colon character thus:
find -name "*.c" -exec ls -l {} \;
这篇关于为什么这个shell命令出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文