|
发表于 2008-4-24 20:55:00
|
显示全部楼层
- Command substitution allows the output of a command to replace the com-
- mand name. There are two forms:
- $(command)
- or
- `command`
- Bash performs the expansion by executing command and replacing the com-
- mand substitution with the standard output of the command, with any
- trailing newlines deleted. Embedded newlines are not deleted, but they
- may be removed during word splitting. The command substitution $(cat
- file) can be replaced by the equivalent but faster $(< file).
- When the old-style backquote form of substitution is used, backslash
- retains its literal meaning except when followed by $, `, or \. The
- first backquote not preceded by a backslash terminates the command sub-
- stitution. When using the $(command) form, all characters between the
- parentheses make up the command; none are treated specially.
复制代码 重要的是最后一段,所以对backslash做出的解释是这个:相当于相当于此时输出自然是第二个问题更好解释,IFS默认值是空格、制表符和新行符三者的序列,其作用之一是用来对命令行分词。如果不将参数用双引号括起来,当被扩展后,原来 ls -l 输出中的newline全部被看成是分词用的词间分割符,也就丢失了;当被扩展后,由于双引号的存在,newline被全部保留,并且送入echo输出。 |
|