Bash中的支架,支架,curl支架

这里是谜语:

如果我做:

touch file{1,2,3} 

它创建file1,file2,file3

如果我这样做

 rm file[1-3] 

它删除了它们。

但如果我这样做

 touch file[1-3] 

它创建:

 file[1-3] 

为什么?

如果您在阅读手册页时遇到麻烦而不是制作谜语:

 Brace Expansion Brace expansion is a mechanism by which arbitrary strings may be generated. This mechanism is similar to pathname expansion , but the filenames generated need not exist. ... 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 filenames matching the pattern (see Pattern Matching below). If no matching filenames are found, and the shell option nullglob is not enabled, the word is left unchanged. ... Pattern Matching Any character that appears in a pattern, other than the special pattern characters described below, matches itself. ... The special pattern characters have the following meanings: ... [...] Matches any one of the enclosed characters. A pair of characters separated by a hyphen denotes a range expression ; any character that falls between those two characters, inclusive, using the current locale's collating sequence and character set, is matched. 

file[1-3]扩展为名为file1file2file3 。 仅当存在匹配文件时才会发生文件名扩展。 如果没有,则模式保持原样。 因此,对于名为file1file2file3 file[1-3]file[1-3]扩展为file1 file2 file3 。 没有这些文件,它不会扩展,并保留为file[1-3] 。 使用{...} ,文件名不必存在,因此无论文件存在或不存在, file{1..3}扩展为file1 file2 file3