-2

As mentioned in several forums and here, on stackoverflow, there's no difference between these two ways of command substituion in shell.

But, there is. Here is a real example:

# this command works fine:
$(cat $LOG_FILE | gawk "(\$1 \$2) > $TIME")

# this one does not:
`cat $LOG_FILE | gawk "(\$1 \$2) > $TIME"`
Community
  • 1
  • 1
Ixanezis
  • 1,631
  • 13
  • 20
  • Possible duplicate of [Shell Programming: What's the difference between $(command) and \`command\`](http://stackoverflow.com/questions/4708549/shell-programming-whats-the-difference-between-command-and-command). The accepted answer there mentions that there are "minor differences such as how backslashes are parsed". – l0b0 Dec 29 '12 at 14:05
  • I reference to the same question, but describe in detail what is the difference in 'how backslashes are parsed', cause at first sight you might think that the difference affects performance or smth unimportant and the result of execution is always the same, thouth it is not. – Ixanezis Dec 29 '12 at 14:16
  • The parsing difference is pointed out in the original answer. If you have any additional information, it might be more useful to point it out there. – l0b0 Dec 29 '12 at 14:59
  • @Ixanezis: what is your question ? – jlliagre Dec 29 '12 at 20:42
  • Ok it was probably better to post my 'answer' in that thread.. – Ixanezis Dec 30 '12 at 21:51

1 Answers1

1

And the whole thing behind this is that when bash sees a first `, it tries to find another one, substituting all \$, \` and \\ on its way,

which leads to replacing \$1 with $1, and then,

when substituting everything inside a "...", $1 is no longer escaped and is treated as the first agrument in a shell script itself (which is an empty string in my case) instead of being passed as $1 to gawk as is.

This is another reason for not using `...` in shell.

Ixanezis
  • 1,631
  • 13
  • 20