Question

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?

Was it helpful?

Solution

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top