【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"
	else
		echo "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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值