Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unix: How can I read multiple lines?

Tags:

shell

unix

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.

like image 343
Strawberry Avatar asked Dec 10 '22 12:12

Strawberry


2 Answers

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)
like image 124
Dennis Williamson Avatar answered Dec 28 '22 23:12

Dennis Williamson


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.

like image 28
Tobu Avatar answered Dec 28 '22 21:12

Tobu