How do I prompt for Yes/No/Cancel input in a Linux shell script?

后端 未结 30 2114
不思量自难忘°
不思量自难忘° 2020-11-22 04:52

I want to pause input in a shell script, and prompt the user for choices.
The standard Yes, No, or Cancel type question.
How d

30条回答
  •  一向
    一向 (楼主)
    2020-11-22 05:19

    yn() {
      if [[ 'y' == `read -s -n 1 -p "[y/n]: " Y; echo $Y` ]];
      then eval $1;
      else eval $2;
      fi }
    yn 'echo yes' 'echo no'
    yn 'echo absent no function works too!'
    

提交回复
热议问题