I've been working with bash for not more than 6 hours, and now I'm trying to create a menu that allows you to do some "fun" stuff :D.
My problem is with the if statement that check if you're in sudo mode. I want to have 3 conditions:
- If I execute the script with sudo mode, I'll be able to enter the path of the folder to be copied.
- If I execute the script without sudo mode, it'll ask me to insert the password, if I do that correctly the script will show me the echo and read op that allows me to write the path of the folder to be copied.
- The same as the point 2, but if I fail the authentication the application will be closed automatically.
Create a copy
2)
if [ "$EUID" -ne 0 ]
then
echo "Checking if you are in sudo mode..."
echo "Error, please insert your password:"
sudo ls /root
if [ "$EUID" -ne 0 ]
then
echo -e "\nCould not authenticate the user."
echo -e "For security reasons the application will be closed."
exit
else
echo "==============================================================="
echo -e "ALL COPIES HAVE A DEFAULT ROUTE: /home/patryk/Desktop/a/"
echo "==============================================================="
echo -e "Enter the path of the folder to be copied: "
read origin
rsync -avzh $origin /home/patryk/Desktop/a/`date-I`
fi
else
echo "==============================================================="
echo -e "ALL COPIES HAVE A DEFAULT ROUTE: /home/patryk/Desktop/a/"
echo "==============================================================="
echo -e "Enter the path of the folder to be copied: "
read origin
rsync -avzh $origin /home/patryk/Desktop/a/`date -I`
fi;;
echo -eseems misdirected. You should probably consider switching toprintfinstead.EUIDwill be switched back to your own aftersudofinishes. It affects only the command you run undersudo, not the remainder of your script. See also stackoverflow.com/questions/37586811/…"$origin"unless you are completely sure that its value cannot ever contain any shell metacharacters. See stackoverflow.com/questions/10067266/…