[英]awk single or double quote usage
Why does the awk command not produce the same results with simple-quotes and double-quotes? 为什么awk命令不能用简单引号和双引号产生相同的结果?
root@vm90:/root# who | awk "{ print $2 }"
...
root@vm90:/root# who | awk '{ print $2 }'
...
I'd like to use awk in a PHP shell_exec() function, which uses simple-quotes in the entire code. 我想在PHP shell_exec()函数中使用awk,它在整个代码中使用简单引号。
This ... 这个 ...
$output = shell_exec("who | awk '{ print $2 }'");
... works, but I prefer ... ......有效,但我更喜欢......
$output = shell_exec('who | awk "{ print $2 }"');
... this, which doesn't work. ......这,这不起作用。
From the GNU Awk manual (emphasis added): 从GNU Awk手册 (重点补充):
Because certain characters within double-quoted text are processed by the shell , they must be escaped within the text. 由于双引号文本中的某些字符由shell处理 ,因此必须在文本中对其进行转义 。 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. (The leading backslash is stripped first.) 值得注意的是字符$
,`
,\\
和"
,如果它们要在字面上传递给程序,则所有字符必须在双引号文本中以反斜杠开头。(首先剥离前导反斜杠。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.