此脚本利用bash内建变量$UID来判断当前用户是否为root用户
#!/bin/bash
#am-i-root.sh
ROOT_UID=0
if [ "$UID" -eq "$ROOT_UID" ]
then
echo "You are root."
else
echo "You are just an ordinary user (but mom loves you as the same)."
fi
exit 0
#==========================================
#another way to judge if you are the root
#ROOTUSER_NAME=root
#username=`id -nu` #or username=`whoami`
#if [ "$username"="$ROOTUSER_NAME" ]
#then
# echo "Rooty,toot,toot.You are root."
#else
# echo "You are just a regular fella."
#fi
阅读(6811) | 评论(0) | 转发(2) |