- 论坛徽章:
- 0
|
- [root@Mylinux tmp]# cat a.txt
- a.txt first
- a.txt First
- [root@Mylinux tmp]# cat first
- first
- First
- [root@Mylinux tmp]# grep '[fF]irst' *.txt
- a.txt first
- a.txt First
- [root@Mylinux tmp]# grep [fF]irst *.txt
- a.txt first
- [root@Mylinux tmp]# rm first
- rm:是否删除 一般文件 “first”? y
- [root@Mylinux tmp]# grep '[fF]irst' *.txt
- a.txt first
- a.txt First
- [root@Mylinux tmp]# grep [fF]irst *.txt
- a.txt first
- a.txt First
- [root@Mylinux tmp]#
复制代码
如果命令是grep [fF]irst *.txt,当存在first文件时,经过Pathname Expansion后,最后的命令是grep first a.txt(如果只有一个.txt文件)
当不存在first文件时,经过Pathname Expansion后,最后的命令是grep [fF]irst a.txt(如果只有一个.txt文件)
Pathname Expansion
After word splitting, unless the -f option has been set, bash scans
each word for the characters *, ?, and [. If one of these characters
appears, then the word is regarded as a pattern, and replaced with an
alphabetically sorted list of file names matching the pattern. If no
matching file names are found, and the shell option nullglob is dis-
abled, the word is left unchanged. If the nullglob option is set, and
no matches are found, the word is removed. If the failglob shell
option is set, and no matches are found, an error message is printed
and the command is not executed. If the shell option nocaseglob is
enabled, the match is performed without regard to the case of alpha-
betic characters. When a pattern is used for pathname expansion, the
character ‘‘.’’ at the start of a name or immediately following a
slash must be matched explicitly, unless the shell option dotglob is
set. When matching a pathname, the slash character must always be
matched explicitly. In other cases, the ‘‘.’’ character is not
treated specially.
[ 本帖最后由 ywlscpl 于 2009-12-18 14:16 编辑 ] |
|