In Bash, how to add “Are you sure [Y/n]” to any command or alias?

前端 未结 17 3001
轮回少年
轮回少年 2020-11-29 15:11

In this particular case, I\'d like to add a confirm in Bash for

Are you sure? [Y/n]

for Mercurial\'s hg push ssh://username@www.example.com//some

17条回答
  •  孤城傲影
    2020-11-29 15:25

    read -r -p "Are you sure? [Y/n]" response
      response=${response,,} # tolower
      if [[ $response =~ ^(yes|y| ) ]] || [[ -z $response ]]; then
          your-action-here
      fi
    

提交回复
热议问题