Reputation: 4539
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 = ?
Upvotes: 10
Views: 50010
Reputation: 189618
ksh
allows you to specify a prompt as part of the read
command using this syntax:
read myName?"Please provide your name: "
Upvotes: 0
Reputation: 1670
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
Upvotes: 8
Reputation: 6656
You want read:
echo Please enter your name:
read name
echo $name
See read(1) for more.
Upvotes: 20