繁体   English   中英

如何将换行符添加到bash脚本中?

[英]How to get a newline character into a bash script?

我有一个bash脚本,其中有一个命令

echo -e $(sort $1 | uniq -d)

从命令行运行此脚本时,所有行都出现在一行中。 如何在此脚本中添加换行符以将所有行分开?

您可能需要引用echo以保持格式:

echo -e "$(sort $1 | uniq -d)"

看一个例子:

$ myvar="hello
> how
> are
> you"

$ echo $myvar     <--- unquoted, loses the format
hello how are you

$ echo "$myvar"   <--- quoted, keeps the format
hello
how
are
you

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM