5.2. read

Use read to take information from the keyboard or from a line of text from a file and assign it to a variable. If you specify only one variable then the read will assign all input to that variable until it sees an end-of-file marker or the shell sees a carriage return.

The general format is:

read variable1 variable2... 

One variable has been specified, which holds all text until the return key has been hit:

						
$ read name 
Hello I am superman 
$ echo $name 
Hello I am superman
					

Here, we assign two variables to hold a first and a second name. The shell will use the space bar as the separator for each variable.

						
$ read name surname 
John Doe 
$ echo $name $surname 
John Doe
					

If you type in too many fields of text, the shell will assign all ...

Get Linux and Unix Shell Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.