推斷是否當前用戶root。假設是暗示root用戶,假設而不是提示對于普通用戶
#!/bin/bash
#title: testus.sh
#author: orangleliu
#date: 2014-08-09
#desc: get current user, if it is root user, tell us it is super user or tell us is a common user#================
#Function CheckUser
#================CheckUser()
{check_user=`whoami`if [ "$check_user" == "root" ]then echo "You are $check_user user"echo "You are a super amdin"elseecho "You are $check_user user"echo "You are a common user"fi
}
#================
#Function Main
#================
Main()
{CheckUser
}Main
運行結果[orangle@localhost shell]$ bash testus.sh?
You are orangle user
You are a common user
[orangle@localhost shell]$ su - root
Password:?
[root@localhost ~]# bash /home/orangle/shell/testus.sh?
You are root user
You are a super amdin
一方面之前沒有系統的寫過shell腳本。一方面是通過小案例來學習和總結shell。
而不是通過各種語法的學習然后再去寫腳本。
參考教程
本文出自?“orangleliu筆記本”?博客。請務必保留此出處http://blog.csdn.net/orangleliu/article/details/38449613
版權聲明:本文orangleliu(http://blog.csdn.net/orangleliu/)原創文章。文章轉載申報。