tags:

views:

60

answers:

2

quick question, how do I write a shell script that prompts users to enter let say 5 lines and it will stores those lines into a .txt file for example,

Today is hot 
Today is code 
Today is chilly
Today is windy
Today is sunny

not like

Today is hot  Today is code  Today is chilly Today is windy today is sunny

Thanks for your help

+2  A: 

In bash you can do:

for i in {1..5}
do
  read line
  echo $line >> file.txt
done
codaddict
thanks for the quick response !!
steven
Or `... read -r line; echo "$line"; done > file.text` - add `-r` to accept backslashes literally, quote the variable to preserve whitespace and do all your output at once.
Dennis Williamson
A: 

Does this count?

sed 5q > file.txt
Jonathan Leffler