Reading user input

To read standard input into a shell script use the read command. For example:

   echo "Please enter your name:"
   read name
   echo "Welcome to Edinburgh $name"

This prompts the user for input, assigns this to the variable name and then displays the value of this variable to standard output.

If there is more than one word in the input, each word can be assigned to a different variable. Any words left over are assigned to the last named variable. For example:

   echo "Please enter your surname\n"
   echo "followed by your first name: \c"
   read name1 name2
   echo "Welcome to Glasgow $name2 $name1"

[Home] [Search] [Index] This site maintained by system@gantep.edu.tr