How do I read multiple lines from STDIN into a variable?
- by The Wicked Flea
I've been googling this question to no avail. I'm automating a build process here at work, and all I'm trying to do is get version numbers and a tiny description of the build which may be multi-line. The system this runs on is OSX 10.6.8.
I've seen everything from using CAT to processing each line as necessary. I can't figure out what I should use and why.
Attempts
read -d '' versionNotes
Results in garbled input if the user has to use the backspace key. Also there's no good way to terminate the input as ^D doesn't terminate and ^C just exits the process.
read -d 'END' versionNotes
Works... but still garbles the input if the backspace key is needed.
while read versionNotes
do
echo " $versionNotes" >> "source/application.yml"
done
Doesn't properly end the input (because I'm too late to look up matching against an empty string).