[Shell] judge the current user
Determines whether the current user is root. If the user is a root user, if not
#!/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
Execution result
[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
On the one hand, no shell scripts have been written by the system before, and on the other hand, shell is learned and summarized through small cases. Instead of learning various syntaxes and then writing scripts.
Reference
This article is from the "orangleliu notebook" blog, please be sure to keep this http://blog.csdn.net/orangleliu/article/details/38449613