简体   繁体   English

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

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

I have a bash script where there is a command 我有一个bash脚本,其中有一个命令

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

When this script is run from the command line, all the rows come out in one line. 从命令行运行此脚本时,所有行都出现在一行中。 How can I get an newline character into this script to get all the lines separated? 如何在此脚本中添加换行符以将所有行分开?

You may need to quote the echo to keep the format: 您可能需要引用echo以保持格式:

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

See an example: 看一个例子:

$ 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