简体   繁体   中英

Unix: How can I read multiple lines?

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 starting 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.

如果换行中不包含换行符,则可以使用“\\”字符来转义输入中的换行符。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM