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