【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
版权声明:本文orangleliu(http://blog.csdn.net/orangleliu/)原创文章。文章转载申报。
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步