2001-07-10 14:25:50 +00:00
|
|
|
#!/bin/bash
|
|
|
|
# am-i-root.sh: Am I root or not?
|
|
|
|
|
|
|
|
ROOT_UID=0 # Root has $UID 0.
|
|
|
|
|
2001-09-04 13:27:31 +00:00
|
|
|
if [ "$UID" -eq "$ROOT_UID" ] # Will the real "root" please stand up?
|
2001-07-10 14:25:50 +00:00
|
|
|
then
|
|
|
|
echo "You are root."
|
|
|
|
else
|
|
|
|
echo "You are just an ordinary user (but mom loves you just the same)."
|
|
|
|
fi
|
|
|
|
|
|
|
|
exit 0
|
2001-09-04 13:27:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
# ============================================================= #
|
|
|
|
# Code below will not execute, because the script already exited.
|
|
|
|
|
|
|
|
# An alternate method of getting to the root of matters:
|
|
|
|
|
|
|
|
ROOTUSER_NAME=root
|
|
|
|
|
2002-04-01 16:04:17 +00:00
|
|
|
username=`id -nu` # Or... username=`whoami`
|
2001-09-04 13:27:31 +00:00
|
|
|
if [ "$username" = "$ROOTUSER_NAME" ]
|
|
|
|
then
|
|
|
|
echo "Rooty, toot, toot. You are root."
|
|
|
|
else
|
|
|
|
echo "You are just a regular fella."
|
|
|
|
fi
|