awk single or double quote usage

awk, php

Solution

From the GNU Awk manual (emphasis added):

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. (The leading backslash is stripped first.)

Problem

Why does the awk command not produce the same results with simple-quotes and double-quotes? ``` 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. This ... ``` $output = shell_exec("who | awk '{ print $2 }'"); ``` ... works, but I prefer ... ``` $output = shell_exec('who | awk "{ print $2 }"'); ``` ... this, which doesn't work.

Original source