How can I make an “are you sure” prompt in a Windows batchfile?

前端 未结 11 1215
时光说笑
时光说笑 2020-12-07 19:43

I have a batch file that automates copying a bunch of files from one place to the other and back for me. Only thing is as much as it helps me I keep accidentally selecting t

11条回答
  •  执笔经年
    2020-12-07 20:25

    Open terminal. Type the following

    echo>sure.sh
    chmod 700 sure.sh
    

    Paste this inside sure.sh

    #!\bin\bash
    
    echo -n 'Are you sure? [Y/n] '
    read yn
    
    if [ "$yn" = "n" ]; then
        exit 1
    fi
    
    exit 0
    

    Close sure.sh and type this in terminal.

    alias sure='~/sure&&'
    

    Now, if you type sure before typing the command it will give you an are you sure prompt before continuing the command.

    Hope this is helpful!

提交回复
热议问题