阅读在bash的变量有一个默认值 [英] Read a variable in bash with a default value
本文介绍了阅读在bash的变量有一个默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在bash脚本来读取来自终端的值。我想是能够提供一个默认值,用户可以更改
I need to read a value from the terminal in a bash script. I would like to be able to provide a default value that the user can change.
# Please enter your name: Ricardo^
在这个脚本的提示是请输入你的名字:默认值是里卡多,光标将默认值之后。有没有办法在bash脚本做到这一点?
In this script the prompt is "Please enter your name: " the default value is "Ricardo" and the cursor would be after the default value. Is there a way to do this in a bash script?
推荐答案
您可以使用参数扩展如
read -p "Enter: " name
name=${name:-Richard}
echo $name
这篇关于阅读在bash的变量有一个默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文