命令 echo 中的反斜杠转义字符

问题描述 投票:0回答:1

谁能解释一下为什么 不能用作换行符?

[user1@localhost ~]$ echo -e a\nb\nc
anbnc
bash quotes
1个回答
0
投票

使用更多引号!

$ echo -e "a\nb\nc"
a
b
c

学习如何在shell中正确引用,这非常重要:

“双引号”包含空格/元字符的每个文字和 every 扩展:

"$var"
"$(command "$var")"
"${array[@]}"
"a & b"
。使用
'single quotes'
表示代码或文字
$'s: 'Costs $5 US'
ssh host 'echo "$HOSTNAME"'
。见
http://mywiki.wooledge.org/Quotes
http://mywiki.wooledge.org/Arguments
https://web.archive.org/web/20230224010517/https://wiki.bash-hackers.org/syntax/words
何时需要双引号

© www.soinside.com 2019 - 2024. All rights reserved.