Chinaunix首页 | 论坛 | 博客
  • 博客访问: 782787
  • 博文数量: 108
  • 博客积分: 2887
  • 博客等级: 少校
  • 技术积分: 1570
  • 用 户 组: 普通用户
  • 注册时间: 2010-11-28 07:51
文章分类

全部博文(108)

文章存档

2012年(4)

2011年(86)

2010年(18)

分类:

2011-03-07 20:34:56

此脚本利用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

阅读(6771) | 评论(0) | 转发(2) |
0

上一篇:shell脚本

下一篇:女生节的祝福

给主人留下些什么吧!~~