-
Book Overview & Buying
-
Table Of Contents
Linux Command Line and Shell Scripting Bible - Third Edition
By :
Although providing command line options and parameters is a great way to get data from your script users, sometimes your script needs to be more interactive. Sometimes you need to ask a question while the script is running and wait for a response from the person running your script. The bash shell provides the read command just for this purpose.
The read command accepts input either from standard input (such as from the keyboard) or from another file descriptor. After receiving the input, the read command places the data into a variable. Here's the read command at its simplest:
$ cat test21.sh
#!/bin/bash
# testing the read command
#
echo -n "Enter your name: "
read name
echo "Hello $name, welcome to my program. "
#
$
$ ./test21.sh
Enter your name: Rich Blum
Hello Rich Blum, welcome to my program.
$
That's pretty simple. Notice that the echo command that produced the prompt uses the -n option. This suppresses the newline...
Change the font size
Change margin width
Change background colour