在 Linux 中,echo
命令默認(rèn)支持轉(zhuǎn)義字符。轉(zhuǎn)義字符以反斜杠(\)開(kāi)頭,用于在命令行中插入特殊字符或控制字符。例如:
\n
代表?yè)Q行符\t
代表制表符\\
代表一個(gè)反斜杠字符(\)本身以下是一些使用轉(zhuǎn)義字符的示例:
echo "Hello, World!\nThis is a new line."
echo -e "Hello, \tWorld!\\nThis is a new line with escaped characters."
輸出:
Hello, World!
This is a new line.
Hello, World!\nThis is a new line with escaped characters.
注意:-e
選項(xiàng)用于解釋轉(zhuǎn)義字符。如果不使用 -e
,echo
會(huì)將反斜杠(\)視為普通字符,而不會(huì)解釋轉(zhuǎn)義字符。