In Linux commands, characters such as $and & are illegal. What if I only want to display these special characters as common symbols? References are needed, and there are three ways to reference them in Linux.
-
Use double quotation marks around “”, but this does not apply to “$”.
echo “Today is $(date)”
-
Enclose all special characters in single quotation marks.
echo ‘Today is $(date)’
-
Backslash \ escape, this is common in many situations.
echo “Today is $(date)”
Output:
[root@localhost ~]# echo "Today is $(date)" Today is Thursday, July 01, 2021 20:27:00 CST [root@localhost ~]# echo 'Today is $(date)' Today is $(date) [root@localhost ~]# echo "Today is \$(date)" Today is $(date)Copy the code