知识屋:更实用的电脑技术知识网站
所在位置:首页 > 操作系统 > linux

linux 判断当前用户是否是root

发布时间:2014-05-22 17:05:15作者:知识屋

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
}
(免责声明:文章内容如涉及作品内容、版权和其它问题,请及时与我们联系,我们将在第一时间删除内容,文章内容仅供参考)
收藏

上一篇:Linux系统进程深入理解

下一篇:rsync+inotify实现多台web数据动态同步操作步骤

相关知识

软件推荐

更多 >

游戏推荐

更多 >

精选栏目

热门推荐

猜你喜欢