How to read a value from user input to a variable

In ksh, how can I suggest a user to enter a value and load that value into a variable in a script?

Command line

echo Please enter your name: 

in script

 $myName = ? 
+6
source share
3 answers

Do you want to read:

 echo Please enter your name: read name echo $name 

See (1) for more details.

+12
source

You can do this in one line, for example:

 read -p "Please enter your name:" myName 

To use a variable in a script

 echo "The name you inputed is: $myName" echo $myName 
+3
source

it is better if you create a myname value with let and the script is as follows:

 #!/bin/bash let myname echo "enter your name : " read myname echo "your name is $myname" 
0
source

All Articles