I want to know why an extra echo will print in my shell. I'm using bash version 4.2.46(1).echo `echo `echo $SHELL``A interesting issue is if I replace '``' with $() it doesn't print extra echo:echo $(echo `echo $SHELL`)And I found that it prints extra echos in odd echo command numbers:echo `echo `echo `echo `echo $SHELL````
Nested echo command in backticks
bash;shell;shell script;echo;command substitution
Your two versions:echo `echo `echo $SHELL``andecho $(echo `echo $SHELL`)are not equivalent. The first backtick command substitution ends as soon as another backtick is seen:When the old-style backquote form of substitution is used, [...] The first backquote not preceded by a backslash terminates the command substitution. Your first version is actually equivalent to:echo $(echo )echo $SHELL$()which is why you get an echo in the output - the command you end up running (after substitutions and with extra whitespace removed) is just:echo echo /bin/bashso the output is echo /bin/bash, just like if you wrote that command out directly.If you must nest backticks, you can backslash the inner pairs to escape them. Your first command could be written correctly as:echo `echo \`echo $SHELL\``although I wouldn't recommend it  $( ... ) is made for nesting.