start page | rating of books | rating of authors | reviews | copyrights

Unix Power ToolsUnix Power ToolsSearch this book

35.18. read: Reading from the Keyboard

The Bourne shell read command reads a line of one or more words from the keyboard (or standard input)[109] and stores the words in one or more shell variables. This is usually what you use to read an answer from the keyboard. For example:

[109]Some early versions of read don't handle < redirection (Section 43.1); they can only read from the terminal.

echo -n "Type the filename: "
read filename

Here is how the read command works:

Some Bourne shells have a built-in function named line that reads a line from standard input and writes it to standard output. Use it with command substitutions (Section 28.14):

value=`line`

Figure Go to http://examples.oreilly.com/upt3 for more information on: grabchars

The grabchars program lets you read from the keyboard without needing to press RETURN.

-- JP



Library Navigation Links

Copyright © 2003 O'Reilly & Associates. All rights reserved.