awk 的语句改为双引号就变成了整行输出,双引号起了什么作用?请教==
awk 的语句改为双引号就变成了整行输出,双引号起了什么作用?请教==
|
1
|
|
ynyounuoMar 22, 2020
2
|
|
ynyounuoMar 22, 2020
3
> Double quotes protect most things between the opening and closing quotes. The shell does at least variable and command substitution on the quoted text. Different shells may do additional kinds of processing on double-quoted text.
> Because certain characters within double-quoted text are processed by the shell, they must be escaped within the text. Of note are the characters ‘$’, ‘`’, ‘\’, and ‘"’, all of which must be preceded by a backslash within double-quoted text if they are to be passed on literally to the program. |
|
widewingMar 22, 2020 via Android
4
shell $2=空字符串
|
|
sakuramansteinMar 22, 2020 via Android
6
看了一下楼上的答案,是不是这个意思 双引号内的字符串先由 shell 解析 于是$2 被解析为空(没有这个变量),等价于 awk "{print}",所以输出 1 2 。
|
|
tldayMar 22, 2020
8
echo '1 2'|awk '{print $2}'
|
|
9
@sakuramanstein 应该是这样的。但是在 awk 中好像没办法打印出文本的美元符了,通过 echo '$1'是可以的,awk 对单双引号的解释和 echo 对其的处理方式完全是相反的。
|
|
sakuramansteinMar 22, 2020 via Android
10
@lasuar 可以啊 awk '{print "$"}'
|
|
11
@sakuramanstein 好的,3q==
|
|
labulaka521Mar 22, 2020 via Android
12
awk 请使用单引号
|