Either I missed some backlash or backlashing does not seem to work with too much programmer-quote-looping.
$ echo "hello1-`echo hello2-\`echo hello3-\`echo hello4\`\``" hello1-hello2-hello3-echo hello4
Wanted
hello1-hello2-hello3-hello4-hello5-hello6-...
The Open Group has a definition for the backtick operator, officially referred to as command substitution. This operator is not the single quote character, but another character known as the grave accent ( ` ).
The manual page for Bash (e.g. man bash ) says that the -c option executes the commands from a string; i.e. everything inside the quotes.
$() means: "first evaluate this, and then evaluate the rest of the line". On the other hand ${} expands a variable. I'm afraid the answer is just that the bash syntax for while just isn't the same as the syntax for for .
The back quote is the one to use when you want to assign output from system commands to variables. It tells the shell to take whatever is between the back quotes as a system command and execute its output. Using these methods you can then substitute the output into a variable.
Use $(commands)
instead:
$ echo "hello1-$(echo hello2-$(echo hello3-$(echo hello4)))" hello1-hello2-hello3-hello4
$(commands)
does the same thing as backticks, but you can nest them.
You may also be interested in Bash range expansions:
echo hello{1..10} hello1 hello2 hello3 hello4 hello5 hello6 hello7 hello8 hello9 hello10
if you insist to use backticks, following could be done
$ echo "hello1-`echo hello2-\`echo hello3-\\\`echo hello4\\\`\``"
you have to put backslashes, \\ \\\\ \\\\\\\\
by 2x and so on, its just very ugly, use $(commands)
as other suggested.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With