如何在 Linux 中建立確認問題?

如何在 Linux 中建立確認問題?

git push server-name我有一個會產生重大後果的命令 ( )。如何要求確認僅此命令?它應該忽略空白。

確認可以是Enter 'yes i am sure.' to confirm:

順便說一下,還有一個不需要確認的指令:git push server-name-staging

答案1

git您要編寫的腳本的別名:

$ alias git=mygit

……它住在你的PATH某個地方,看起來像這樣:

#!/bin/sh
if [ "$1" = "push" ]
then
    /bin/echo -n "Enter 'yes i am sure.' to confirm: "
    read answer
    if [ "$answer" != "yes i am sure." ]
    then
        echo So indecisive...
        exit 1
    fi
fi

git "$@"

相關內容