I've hacked together this bash script which tests if the user has superuser privileges and if they don't it asks for them. Ultimately I'm trying to invert the second 'if' statement so that I can remove the following two lines (the echo "password ok" and the else on the following line)
# Root user only if [[ "$EUID" != 0 ]]; then sudo -k # make sure to ask for password on next sudo if sudo true; then echo "Password ok" else echo "Aborting script" exit 1 fi fi echo "do my ops"
Is the purpose of "true" on the fourth line just a null-statement?
I need to invert the test on the fourth line, how do I do so? Here is what I've tried:
if sudo false; then if sudo true == false; then if [!(sudo true)]; then