文章出處
文章列表
文件名: test26.sh
#!/bin/bash # getting just one character of input read -n1 -p "Do you want to continue [Y/N]? " answer case $answer in Y | y) echo echo "fine,continue on...";; N | n) echo echo OK, goodbye exit;; esac echo "This is the end of script"
運行 sh test26.sh
出現 Do you want to continue [Y/N]?
輸入 y 后
fine,continue on...
This is the end of script
輸入 n 后
OK, goodbye
該例子使用了-n選項,后接數字1,指示read命令只要接收到一個字符就退出,只要按下一個字符進行回答,read命令立即接受輸入并將其傳給變量,無需按回車鍵
文章列表
全站熱搜