Created
August 12, 2021 22:41
-
-
Save yunginnanet/a03629b5c374d0d180f0c9221958bc66 to your computer and use it in GitHub Desktop.
test for sudo capability in bash
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
#!/usr/bin/env bash | |
echo "" | |
echo "can we sudo?" | |
echo "" | |
if [[ ! $(sudo echo 0) ]] | |
then | |
echo "nope." | |
exit 1 | |
else | |
set -x | |
sudo whoami | |
{ set +x; } 2>/dev/null | |
echo "" | |
echo "sure can." | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment