Skip to content

Instantly share code, notes, and snippets.

@trongnghia203
Last active June 26, 2020 14:41
Show Gist options
  • Save trongnghia203/40a0c503e3ae84b023bd4cf39d4d110c to your computer and use it in GitHub Desktop.
Save trongnghia203/40a0c503e3ae84b023bd4cf39d4d110c to your computer and use it in GitHub Desktop.
Bash: Yes/No Confirm script - Advanced
#!/bin/bash
# Author: Nghia Le <trongnghia203@gmail.com>
# 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