开发者

Unix: How can I read multiple lines?

开发者 https://www.devze.com 2023-01-27 12:00 出处:网络
So it seems read command only takes 1 line, what if I wanted to input a short paragraph with line breaks? What would I use? I think there\'s a command that ends when you press ctrl+d, so it return key

So it seems read command only takes 1 line, what if I wanted to input a short paragraph with line breaks? What would I use? I think there's a command that ends when you press ctrl+d, so it return key is used for startin开发者_运维技巧g a new paragraph.


text=$(cat)

Allows you to type text with newlines, terminated by a Ctrl-d at the beginning of a line.

The equivalent in Bash, without needing to use an external utility is

text=$(</dev/stdin)


You could drop the user into their favorite editor, with commented text that explains what information is needed and how to make paragraph breaks. That's how most vcs commits work. See ldapvi for a more sophisticated example of this kind of interface.


If line breaks are not essential in the result, you can use '\' character to escape newlines in input.

0

精彩评论

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