Skip to content

Instantly share code, notes, and snippets.

@yunginnanet
Created August 12, 2021 22:41
Show Gist options
  • Save yunginnanet/a03629b5c374d0d180f0c9221958bc66 to your computer and use it in GitHub Desktop.
Save yunginnanet/a03629b5c374d0d180f0c9221958bc66 to your computer and use it in GitHub Desktop.
test for sudo capability in bash
#!/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