如何打印新行?这只会打印\n:
$ echo -e "Hello,\nWorld!"
Hello,\nWorld!
如何打印新行?这只会打印\n:
$ echo -e "Hello,\nWorld!"
Hello,\nWorld!
当前回答
str='hello\nworld'
$ echo | sed "i$str"
hello
world
其他回答
改用printf:
printf "hello\nworld\n"
printf在不同环境中的表现比echo更一致。
确保你在巴什。
$ echo $0
bash
这四种方式对我都有效:
echo -e "Hello\nworld"
echo -e 'Hello\nworld'
echo Hello$'\n'world
echo Hello ; echo world
你可以一直做回声“”。
例如
echo "Hello,"
echo ""
echo "World!"
简单地键入
echo
获得一条新线路
echo $'hello\nworld'
印刷品
hello
world
$“”字符串使用ANSI C报价:
$‘string’形式的单词被特别对待。单词扩展为字符串,并按照ANSI C标准的规定替换反斜杠转义字符。