Interacting with the User
You now know how to assign variables to contain different data; but without input from the user, your variables won’t ever change. The shell provides a way for you to get input from STDIN. Normally, this input will be typed in by the user (or received from a file if STDIN has been redirected). The command that can read input from a user is read. Listing 10.3 shows a slightly modified version of the “Hello World!” program that reads some input from STDIN, which is normally the keyboard, and then acts on that input.
Listing 10.3. Reading Input from STDIN
1. #!/bin/sh 2. 3. # Modified Hello World program that accepts input from keyboard 4. 5. echo 6. echo -n "Please enter your name: " 7. read name 8. echo 9. echo "Hello, ... |
Get FreeBSD6 Unleashed 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.