# 組/用戶是否存在
## 用戶是否存在
```
user="root"
# 如果用戶不存在就添加
egrep "^$user" /etc/passwd >& /dev/null
if [ $? -ne 0 ]
then
useradd $user
fi
```
## 用戶組是否存在
```
group="git"
# 如果用戶組不存在就添加
egrep "^$group" /etc/group >& /dev/null
if [ $? -ne 0 ]
then
groupadd $group
fi
```
# 當前用戶是否為root
## whoami
```
if [ `whoami` = "root" ];then
echo "root用戶!"
else
echo "非root用戶!"
fi
```
## id -u
```
if [ `id -u` -eq 0 ];then
echo "root用戶!"
else
echo "非root用戶!"
fi
```