Reputation: 5344
I am trying to read an entire file into a variable without removing any characters. I'm sure this has to be stupid simple.
This doesn't work, since it removes repeating spaces, all tabs and newlines:
$ echo 'fred wilma' > somefile; z=$(cat somefile); echo $z
fred wilma
I can see the same filtering happening with simple assignment like this:
$ z='fred wilma'; echo $z
fred wilma
but not when I do this:
$ echo 'fred wilma'
fred wilma
How do I get a bash variable to stop being parsed and filtered upon assignment?
Upvotes: 4
Views: 386
Reputation: 76908
Figured it out:
echo 'fred wilma' > somefile; z=$(cat somefile); echo "$z"
Upvotes: 2