开发者

linux shell script input line

开发者 https://www.devze.com 2023-01-18 09:41 出处:网络
quick question, how do I write a shell script that prompts users to enter let say 5lines and it will stores those lines into a .t开发者_开发知识库xt filefor example,

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 .t开发者_开发知识库xt 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


In bash you can do:

for i in {1..5}
do
  read line
  echo $line >> file.txt
done


Does this count?

sed 5q > file.txt
0

精彩评论

暂无评论...
验证码 换一张
取 消