bash user input if

前端 未结 5 1148
没有蜡笔的小新
没有蜡笔的小新 2020-12-25 12:54

I am tring to do simple

Do you want to do that? [Y,n] _

question in bash.

i tried

echo \"Do that? [Y,n]\"
read DO_T         


        
5条回答
  •  情深已故
    2020-12-25 13:37

    You might consider explicit prompting: -p and specifying 1-character-input -n1 which allows to insert y without ENTER.

    read -n1 -p "Do that? [y,n]" doit 
    case $doit in  
      y|Y) echo yes ;; 
      n|N) echo no ;; 
      *) echo dont know ;; 
    esac
    

提交回复
热议问题