简体   繁体   中英

How to get a newline character into a bash script?

I have a bash script where there is a command

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 -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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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