我们经常在shell脚本中会涉及交互输入,这里列举了一些read的常用脚本方便扩展。 原理关于read命令的介绍可以看Shell的read指令 read是最常用的交互输入命令,并且shell基本都能支持。 用例提示输入:1read -p "Do you understand this script? " content 提示输入密码:12read -s -p "Do you know what to enter? " passwordecho "Success!" 提示输入:是/否12345678while true; do read -p "Do you understand this script?: [Y/n] " yn case ${yn} in [Yy]*|'' ) echo "YES!"; break;; [Nn]* ) echo "NO!"; break;; * ) echo "Please answer yes or no.";; esacdone Please enable JavaScript to view the comments powered by Disqus. Blog comments powered by Disqus