Bash script echo seems to remove my new lines? [duplicate]

懵懂的女人 提交于 2020-01-17 06:42:48

问题


This is the contents of my file file.txt:

header
a
b
c

I have no idea what is going on. This command does not print new lines.

echo -e $(tail -n +2 file.txt)

This prints:

a b c

But if you write it to file you will clearly see new lines:

tail -n +2 file.txt >> new_file.txt

test.txt

a
b
c

How do I force echo to print the new lines? I don't think I can use printf here without making some kind of loop.


回答1:


Echo statement within quotes give your output with newline terminated lines. Here is the code

echo -e "$(tail -n +2 file.txt)"


来源:https://stackoverflow.com/questions/44657293/bash-script-echo-seems-to-remove-my-new-lines

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!