Sunday, April 28, 2024
45
rated 0 times [  45] [ 0]  / answers: 1 / hits: 79587  / 2 Years ago, tue, august 23, 2022, 8:19:19

If I have the file input.txt containing:



hello
world
!


Then executing the bash command echo $(cat input.txt) will output this:



hello world !


Why and how can I fix it to output exactly what is in the file how it is in the file?


More From » command-line

 Answers
1

If you use



echo "$(cat input.txt)"


it will work correctly.



Probably the input of echo is separated by newlines, and it will handle it as separate commands, so the result will be without newlines.


[#39312] Tuesday, August 23, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ofunn

Total Points: 164
Total Questions: 116
Total Answers: 116

Location: Liberia
Member since Fri, Oct 22, 2021
3 Years ago
;