|
发表于 2009-3-7 23:04:33
|
显示全部楼层
Post by fmying;1957542
请问这是为什么呢?难道是[color="Red"]echo自己会将变量中的*自动变成当前目录下所有[color="Red"]隐藏文件?或者就是变量设定的时候会自动扩展*?
呃哦,echo自己可不会扩展,都是shell做的(手误吧?);*可不会扩展出当前目录下的隐藏文件。如果你纠正一下你的提问,那么答案就是你所说的前一种情况。
熟悉bash的命令行处理的扩展顺序(如果你读过O'Reilly的Learning the bash Shell的ch7应该会记得里面有张复杂的命令行处理顺序流图,不过要完全记住不太可能)。
如果没看过,或者忘记了处理细节,那也没有关系,看bash手册页也可以学习和参考,没那么直观而已:- EXPANSION
- Expansion is performed on the command line after it has been split into
- words. There are seven kinds of expansion performed: brace expansion,
- tilde expansion, parameter and variable expansion, command substitu-
- tion, arithmetic expansion, word splitting, and pathname expansion.
- The order of expansions is: brace expansion, tilde expansion, parame-
- ter, variable and arithmetic expansion and command substitution (done
- in a left-to-right fashion), word splitting, and pathname expansion.
复制代码 顺序就是:
- 扩展a{b,c}d这样的括号扩展;
- 扩展~username为username家目录路径;
- 扩展$打头的那些东西;
- 对上述扩展后的结果进行分词;
- 对重新分词后的命令行执行路径名扩展,就是我们在这里讨论的东西。
|
|