Programming Tutorials

read Statement in Linux Shell Script

By: Vivek G. in Linux Tutorials on 2011-01-09  

Use to get input (data from user) from keyboard and store (data) to variable.


read variable1, variable2,...variableN

Following script first ask user, name and then waits to enter name from the user via keyboard. Then user enters name from keyboard (after giving name you have to press ENTER key) and entered name through keyboard is stored (assigned) to variable fname.

$ vi sayH
        #Script to read your name from key-board
        echo "Your first name please:"
        read fname
        echo "Hello $fname, Lets be friend!"

Run it as follows:

$ chmod 755 sayH $ ./sayH
Your first name please: vivek
Hello vivek, Lets be friend!

Add Comment

* Required information


No comments yet. Be the first!

Most Viewed Articles (in Linux )

Latest Articles (in Linux)