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

我是研究僧i 提交于 2019-12-10 13:13:26

问题


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 = ?

回答1:


You want read:

echo Please enter your name:
read name
echo $name

See read(1) for more.




回答2:


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


来源:https://stackoverflow.com/questions/6802848/how-do-i-read-a-value-from-user-input-into-a-variable

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!