Last active
June 26, 2020 14:41
-
-
Save trongnghia203/40a0c503e3ae84b023bd4cf39d4d110c to your computer and use it in GitHub Desktop.
Bash: Yes/No Confirm script - Advanced
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Author: Nghia Le <[email protected]> | |
# Description: | |
# - To make user confirm the privilege which they are using to run a bash script | |
# by asking user if they're sure and wanted to run this bash script as current log-in user. | |
read -n 1 -p "Do you want to run this bash script as $(whoami)? Yes/[No]: " YES_NO | |
echo -e "\n" | |
if [ -z ${YES_NO} ] || [ ${YES_NO} = "No" ] || [ ${YES_NO} = "no" ] || [ ${YES_NO} = "N" ] || [ ${YES_NO} = "n" ]; then | |
echo "You select No, then it is going to exit now... " | |
sleep 1 | |
echo -e "\nGood bye now..!!!\n" | |
sleep 1 | |
exit 1 | |
elif [ ${YES_NO} = "Yes" ] || [ ${YES_NO} = "yes" ] || [ ${YES_NO} = "Y" ] || [ ${YES_NO} = "y" ]; then | |
read -n 1 -p "Are you really sure? Yes/[No]: " YES_NO2 | |
echo -e "\n" | |
if [ -z ${YES_NO2} ] || [ ${YES_NO2} = "No" ] || [ ${YES_NO2} = "no" ] || [ ${YES_NO2} = "N" ] || [ ${YES_NO2} = "n" ]; then | |
echo "You select No, then it is going to exit now... " | |
sleep 1 | |
echo -e "\nGood bye now..!!!\n" | |
sleep 1 | |
exit 1 | |
elif [ ${YES_NO2} = "Yes" ] || [ ${YES_NO2} = "yes" ] || [ ${YES_NO2} = "Y" ] || [ ${YES_NO2} = "y" ]; then | |
echo "Look likes you're pretty to to run bash script as $(whoami)..." | |
sleep 2 | |
echo -e "\nHmmmm, hummm..." | |
sleep 2 | |
echo -e "\nOkey, then it is going to run the bash script now... after 5 seconds" | |
sleep 3 | |
echo -e "\n2 seconds now..." | |
sleep 2 | |
echo -e "\nDeploying...\n" | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment