Download Shells: User's Guide

Transcript
read
read
Syntax
24
For POSIX Shell only (note that name must be specied):
2
3
read -r name ...
For Korn Shell only:
2
2
3 32
32
3
name?prompt name . . .
This shell input mechanism reads a line from standard input and places each
word into the parameter name using the separator specied by the IFS shell
parameter. If name s are not specied, the line is read into the Korn Shell
REPLY variable (see select). If the ?prompt is included the user is prompted
interactively with prompt . The denitions of the options are:
-p
Read from the output of the process spawned with |&.
-r
Do not interpret the \ at the end of a line as line continuation.
-s
Put the input line into the history le.
-un
Read the input from le descriptor n .
read -prsu n
Example
$ echo 'What is your name? \c'
$ read name
$ echo "Hello, $name . . . "
The rst line prints a prompt and leaves the cursor one blank to the right of
the ?. The next line reads in text from the user and saves it in $name. Last, a
line is printed which includes the value of $name (since the string is in double,
not single, quotes).
read field1 field2 junk
This reads the rst whitespace-separated word from an input line into $field1,
the second into $field2, and the rest into $junk, which is presumably ignored.
Part III:
POSIX and Korn Shell
FINAL TRIM SIZE : 7.5 in x 9.0 in
Command Reference
24-27