Reading Lines with read
The read command is one of the most important ways to get information into a shell program:
$x=abc ; printf "x is now '%s'. Enter new value: " $x ; read x
x is now 'abc'. Enter new value:PDQ
$echo $x
PDQ
read can read values into
multiple variables at one time. In this case, characters in $IFS
separate the
input line into individual words. For example:
printf "Enter name, rank, serial number: " read name rank serno
A typical use is processing the /etc/passwd
file. The standard format is seven colon-separated fields: username, ...
Get Classic Shell Scripting 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.