Linux 如何将用户输入的值读入变量
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6802848/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 05:14:10 来源:igfitidea点击:
How do I read a value from user input into a variable
提问by Justin
In ksh, how do I prompt a user to enter a value, and load that value into a variable within the script?
在 ksh 中,如何提示用户输入一个值,并将该值加载到脚本中的变量中?
command line
命令行
echo Please enter your name:
within the script
在脚本中
$myName = ?
采纳答案by Marcus Borkenhagen
回答by thebunnyrules
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