bash中花括号{1..10}的注意事项
bash shell中,我们执行echo {1..10},会打印1-10这些数字
[root@localhost ~]# echo {1..10}
1 2 3 4 5 6 7 8 9 10
但是有个前提,这其中的{1..10}
不能带上引号,单双引号,反引号都不行。这是花括号的实现限制,如果想仔细了解,man bash,搜索Brace Expansion看这样一段话
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. Patterns to be brace expanded take the form of an optional preamble, followed by either
a series of comma-separated strings or a sequence expression between a pair of braces, followed by an optional postscript. The
preamble is prefixed to each string contained within the braces, and the postscript is then appended to each resulting string,
expanding left to right.
Brace expansions may be nested. The results of each expanded string are not sorted; left to right order is preserved. For exam‐
ple, a{d,c,b}e expands into `ade ace abe'.
A sequence expression takes the form {x..y[..incr]}, where x and y are either integers or single characters, and incr, an
optional increment, is an integer. When integers are supplied, the expression expands to each number between x and y, inclusive.
Supplied integers may be prefixed with 0 to force each term to have the same width. When either x or y begins with a zero, the
shell attempts to force all generated terms to contain the same number of digits, zero-padding where necessary. When characters
are supplied, the expression expands to each character lexicographically between x and y, inclusive. Note that both x and y must
be of the same type. When the increment is supplied, it is used as the difference between each term. The default increment is 1
or -1 as appropriate.
我只是复制了一小段,详情可以自己翻看,总之记住这个就可以了。