声明:本文内容整理自互联网,本人不保留任何权力。
#!/bin/bash
# function: tell effect user is root;
# update: 2017-05-02
###1.利用$()的命令替换
if [ "$(whoami)" == "root" ]
then
echo "root";
fi
# [ 是保留字符,两边要加空格!
if [ "`whoami`" == "root" ]
then
echo "root";
fi
###2.利用bash内置变量EUID(effect uid)
if [[ $EUID -eq 0 ]]
then
echo "root";
fi
###3.利用id命令
if [ "$(id -u)" == "0" ]
then
echo "root";
fi
if [ $(id -u) -eq 0 ]
then
echo "root";
fi
###4. 利用whoami命令
if [ `whoami` = "root" ]
then
echo "root";
fi