[Shell]判斷目前使用者
判斷目前使用者是否為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