The read command is useful in scripts when reading or asking an input from user. This read command is used when the script want to interact with user for his inputs to contunue the script.

read command syntax
read VARIABLE

Example1: Read a value from user input.

read VAR1

To display this value we have to use echo command.

echo $VAR1

Example2: Reading two words/variable/values at a time.

read VAR1 VAR2

Example3: Reading multiple values at a time.

read VAR1 VAR2 VAR3 VAR4

Example4: Read values in to an Array

read VAR1
ARR1=(VAR1)

to display first value in array use below command

echo ${ARR1[0]}

Example5: Read values from a command

read VAR1 VAR2 VAR3 << ( echo surendra kumar anne )
 echo "Enter values are $VAR1 $VAR2 $VAR3"

Example6: Read user input and give some info to user what he has to give. For this use -p option to display some info when reading value.

read -p "Please enter one to ten numbers: " VAL1

Note: You no need to echo command to display information to user, you can achieve that one using read -p option.

Example7: Read have inbuilt variable called REPLY. This is system variable which stores read value in to $REPLY.

read -p "Please enter a value"
echo "Enter value is $REPLY"
Please share your thoughts on this. We will see other scripting related to postings at http://scripting.linuxnix.com.