In addition to variables ($), double quotes (" ") still allow the terminal to interpret a few specific "magic" characters. These are the most common ones:
1. Backticks (`) - Command Substitution
The terminal will execute whatever is inside the backticks and put the result into your text.
- Try this:
echo "Today is \date`"` - Result: It will print "Today is" followed by the actual current date and time.
2. Dollar Sign with Parentheses ($( ))
This is the modern way to do the same thing as backticks. It runs a command inside the string.
- Try this:
echo "My current directory is $(pwd)" - Result: It will tell you exactly where you are in the system (e.g.,
/home/labex/project).
3. Backslash (\) - The Escape Character
The backslash allows you to use a special character (like a quote or a dollar sign) as plain text inside double quotes.
- Try this:
echo "The cost is \$100" - Result:
The cost is $100(The\hides the "magic" of the$). - Try this:
echo "He said \"Hello\"" - Result:
He said "Hello"(The\lets you put quotes inside quotes).
4. History Expansion (!) - Sometimes
In some terminal setups, the exclamation mark ! can cause an error inside double quotes because the system thinks you are trying to refer to a previous command (history).
- This is why many Linux users prefer single quotes if they just want to print a simple exclamation mark!
Summary
Inside double quotes, the terminal is still "listening" for:
$(Variables or Commands)`(Commands)\(Escape instructions)
If you want the terminal to stop listening to everything and just print the text, use single quotes (' ') instead!