Words of the form $aqstringaq are treated specially. The word expands to string, with backslash-escaped characters replaced as specified by the ANSI C standard. Backslash escape sequences, if present, are decoded as follows:
\a
alert (bell)
\b
backspace
\e
an escape character
\f
form feed
\n
new line
\r
carriage return
\t
horizontal tab
\v
vertical tab
\\
backslash
\aq
single quote
\nnn
the eight-bit character whose value is the octal value nnn (one to three digits)
\xHH
the eight-bit character whose value is the hexadecimal value HH (one or two hex digits)
\cx
a control-x character
shell小白一只,简单test了一下:
Shell script的输出是:
具体$和不加$造成上述输出的原理我也不清楚,求其他大神解答~
加$符号将现执行'\n'转义,既将单引号''内的\n转为换行.而$则是获取这个转义后的结果,既为一个空行.
如果不使用$的话,eho "$IFS"将打印原始字符,因为"'\n'"中的'\n'被视作一个普通字符串.