Depends on your version of bash
:
bash-4.2$ echo `echo \`echo "uh!"\``
bash: !"\``: event not found
bash-4.3$ echo `echo \`echo "uh!"\``
uh!
In bash-4.3
, !"
is no longer eligible as a history event designator, so history expansion does not apply.
Other than that, it's just normal backtick nesting syntax. Inside backticks, the backslash character is overloaded (yet again) to do that nested expansion again.
You can nest as many levels as you want:
echo `echo \`echo \\\`echo \\\\\\\`echo whatever\\\\\\\`\\\`\``
Which is the cumbersome equivalent of:
echo $(echo $(echo $(echo $(echo whatever))))
However note that in both versions, the command substitution is subject to word splitting. So, you'd want to quote them to prevent it.
With bash
, dash
, pdksh
, yash
, zsh
, it's relatively easy:
echo "`echo "\`echo "\\\`echo "\\\\\\\`echo whatever\\\\\\\`"\\\`"\`"`"
With the Bourne or Korn shell, you also need to escape the "
though, so that becomes:
echo "`echo \"\`echo \\\"\\\`echo \\\\\\\"\\\\\\\`echo whatever\\\\\\\`\\\\\\\"\\\`\\\"\`\"`"
Compare with:
echo "$(echo "$(echo "$(echo "$(echo whatever)")")")"