歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux技術 >> linux 判斷當前用戶是否是root

linux 判斷當前用戶是否是root

日期:2017/3/1 18:04:38   编辑:Linux技術
linux 中,如何判斷當前用戶是否是root 呢?
判斷當前用戶是否是root

復制代碼代碼如下:
#---------------------------- root user check ---------------------start
if [ `id -u` -ne 0 ]; then
echo "Please re-run ${this_file} as root."
exit 1
fi
#---------------------------- root user check ---------------------end
if [ x"$USER" = x"" ];then
if id |grep "^uid=0(root)">/dev/null ;then
:
else
echo "Please rerun `basename $0` as root ."
exit 1
fi
else
if [ ! x"$USER" = x"root" ];then
echo "Please rerun `basename $0` as root ."
exit 1
fi
fi
#=============== check current user start ================
if [ ! $USER = root ];then
echo "Please rerun this script as root ."
exit 1
fi
#=============== check current user end ================
#!/bin/sh
if id |grep "^uid=0(root)">/dev/null ;then
echo is root
else
echo not root
fi
check_user(){
if [ $UID -ne 0 ];then
echo "Current user is not ROOT."
echo "Please rerun the installer as Root user."
exit 11
fi
}
Copyright © Linux教程網 All Rights Reserved