Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I read a value from user input into a variable

Tags:

linux

unix

ksh

In ksh, how do I prompt a user to enter a value, and load that value into a variable within the script?

command line

echo Please enter your name: 

within the script

$myName = ?
like image 427
Justin Avatar asked Jul 23 '11 19:07

Justin


2 Answers

You want read:

echo Please enter your name:
read name
echo $name

See read(1) for more.

like image 187
Marcus Borkenhagen Avatar answered Sep 30 '22 19:09

Marcus Borkenhagen


You can do it in a single line, like so:

read -p "Please enter your name:" myName

To use variable in script

echo "The name you inputed is: $myName"
echo $myName
like image 29
thebunnyrules Avatar answered Sep 30 '22 20:09

thebunnyrules