- 论坛徽章:
- 0
|
本帖最后由 想尼尼 于 2013-10-30 17:16 编辑
当前文件夹有a1,a2,a3,b1,b2,b*几个文件。我用find找文件:
(1)find . -name '[ab]*' 正确
(2)find . -name \[ab]* 正确
(3)find . -name [ab]* 出错
man find中说
−name pattern
Base of file name (the path with the leading directories removed) matches shell pattern pattern.
我理解是进行man bash中说的那几种扩展中的Pattern Matching。
第(1)(3)种情况,用单引号括起来,我理解是执行这个命令时,shell会对-name的参数进行扩展,也就是说传给-name的是扩展后的值,
所以要quoted后才保证-name接收的原pattern。
我不明白第(2)种情况,这种backslash的应用方法是怎么回事。
man bash中Pattern Matching这一小节说
Any character that appears in a pattern, other than the special pattern characters described below, matches
itself. The NUL character may not occur in a pattern.
A backslash escapes the following character;
the escaping backslash is discarded when matching. The special pattern characters must be quoted if theyare
to be matched literally.
既然backslash只转义一个character,为什么第(2)中情况会正确呢?
不知道是不是特浅显的问题?勿喷,求解答
|
|