Hello Feixy

在脚本中,判断执行者是否为root。

判断方法1,

#!/bin/bash
if [ `whoami` != "root" ];then
echo " only root can run me"
exit 1
fi 

判断方法2(但是用sudo执行回报脚本有语法错误,不知为何,有知道的高手请回复我)。

if [ $UID == 0 ];then
echo "you are root"
fi

 

posted on 2015-07-25 11:48  飞翔雨  阅读(4849)  评论(0编辑  收藏  举报