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 = ?
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 = ?
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
-p
is not POSIX –
Jodoin ksh
does not support read -p
(or rather, the -p
option to read
does something different in ksh
). This question is clearly tagged ksh and it is reinforced in the question text, but you still provided a Bash answer. –
Housing ksh
allows you to specify a prompt as part of the read
command using this syntax:
read myName?"Please provide your name: "
© 2022 - 2024 — McMap. All rights reserved.