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

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

当前回答

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

$ (echo hello; echo world)
hello
world

其他回答

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

$ (echo hello; echo world)
hello
world
echo $'hello\nworld'

印刷品

hello
world

$“”字符串使用ANSI C报价:

$‘string’形式的单词被特别对待。单词扩展为字符串,并按照ANSI C标准的规定替换反斜杠转义字符。

我的脚本:

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:

这让我到了那里。。。。

outstuff=RESOURCE_GROUP=[$RESOURCE_GROUP]\\nAKS_CLUSTER_NAME=[$AKS_CLUSTER_NAME]\\nREGION_NAME=[$REGION_NAME]\\nVERSION=[$VERSION]\\nSUBNET-ID=[$SUBNET_ID]
printf $outstuff

产量:

RESOURCE_GROUP=[akswork-rg]
AKS_CLUSTER_NAME=[aksworkshop-804]
REGION_NAME=[eastus]
VERSION=[1.16.7]
SUBNET-ID=[/subscriptions/{subidhere}/resourceGroups/makeakswork-rg/providers/Microsoft.Network/virtualNetworks/aks-vnet/subnets/aks-subnet]

改用printf:

printf "hello\nworld\n"

printf在不同环境中的表现比echo更一致。