如何打印新行?这只会打印\n:

$ echo -e "Hello,\nWorld!"
Hello,\nWorld!

当前回答

使用jq:

$ jq -nr '"Hello,\nWorld"'
Hello,
World

其他回答

对于所问的问题(不是特殊字符等),只将双引号改为单引号。

echo -e 'Hello,\nWorld!'

结果如下:

Hello,
World!

你也可以使用带括号的echo,

$ (echo hello; echo world)
hello
world

我的脚本:

echo "WARNINGS: $warningsFound WARNINGS FOUND:\n$warningStrings

输出:

WARNING : 2 WARNINGS FOUND:\nWarning, found the following local orphaned signature file:

在我的Bash脚本中,我一直像你一样生气,直到我尝试了:

echo "WARNING : $warningsFound WARNINGS FOUND:
$warningStrings"

只需按Enter键即可插入跳转。现在的输出是:

WARNING : 2 WARNINGS FOUND:
Warning, found the following local orphaned signature file:

这最好作为

x="\n"
echo -ne $x

-e选项将解释转义序列的反斜杠-n选项将删除输出中的尾随换行符

PS:命令echo的效果是始终在输出中包含一个尾随换行符,因此需要-n来关闭该功能(并使其不那么混乱)

要打印带有回音的新行,请使用:

echo

or

echo -e '\n'