文章出處

 

文件名: 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命令立即接受輸入并將其傳給變量,無需按回車鍵


文章列表




Avast logo

Avast 防毒軟體已檢查此封電子郵件的病毒。
www.avast.com


arrow
arrow
    全站熱搜
    創作者介紹
    創作者 大師兄 的頭像
    大師兄

    IT工程師數位筆記本

    大師兄 發表在 痞客邦 留言(0) 人氣()