[Shell] judge the current user

Source: Internet
Author: User

[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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.