The read statement in shell

read statement


It is used to get the input from keyboard and store to variable.
Syntax is as follows:
read var1, var2,...varN

Above given script will ask user, to input from keyboard a number, character or string.

The script given below will ask user to input his name and then will wait to enter name via keyboard. After that user will enter his name from keyboard (after giving name he have to hit ENTER key on keyboard) and then the entered name through keyboard will be stored to variable name.

$ cat > SayHi
#
#Script to read your the name of user from key-board
#
echo -n "Enter your first name :"
read name
echo "Hello $name, How are you today?"

Output : 

0 Comments:

Post a Comment