[bash]判断当前用户是否为root

来源:互联网 发布:播放软件大全排行 编辑:程序博客网 时间:2024/06/08 18:34
声明:本文内容整理自互联网,本人不保留任何权力。
#!/bin/bash# function: tell effect user is root;# update: 2017-05-02###1.利用$()的命令替换if [ "$(whoami)" == "root" ]then    echo "root";fi# [ 是保留字符,两边要加空格!if [ "`whoami`" == "root" ]then    echo "root";fi###2.利用bash内置变量EUID(effect uid)if [[ $EUID -eq 0 ]]then    echo "root";fi###3.利用id命令if [ "$(id -u)" == "0" ]then    echo "root";fiif [ $(id -u) -eq 0 ]then    echo "root";fi###4. 利用whoami命令if [ `whoami` = "root"then    echo "root";fi
0 0
原创粉丝点击