1

I have a program that is trying to print multiple lines from a text document. I have my main bash program, and I am using the line:

    Multlines=`</Users/$USER/Documents/text.txt`

    echo $Multlines

Where text.txt may look something like

    John
    Smith

but the echo prints John Smith where I want it to print it on different lines. How do I print it out that way?

dizee
  • 33
  • 3
  • While you now have an answer to this question, it seems to me that this may be an [XY Problem](http://mywiki.wooledge.org/XyProblem). Can you explain what you're hoping to achieve by solving this particular problem? There is almost certainly a better way than the one you're using. – ghoti Aug 29 '15 at 16:17
  • @ghoti I am fairly new to bash, and I have just decided to create a text based game on bash. I have already done a couple on C++ and other languages, but this one I decided to be more of an RPG, and I wanted to add ASCII Art but without the hassle of entering the same image over and over again in the text. – dizee Aug 29 '15 at 17:37

2 Answers2

1

To preserve the newline characters in the variable when printing with echo, you need to double quote it:

echo "$Multlines"
janos
  • 120,954
  • 29
  • 226
  • 236
0

You could also just use cat instead of echo, assuming you had it available to you.

devoxel
  • 76
  • 1
  • 5