am-i-root.sh

来自「Shall高级编程」· Shell 代码 · 共 30 行

SH
30
字号
#!/bin/bash# am-i-root.sh:   Am I root or not?ROOT_UID=0   # Root has $UID 0.if [ "$UID" -eq "$ROOT_UID" ]  # Will the real "root" please stand up?then  echo "You are root."else  echo "You are just an ordinary user (but mom loves you just the same)."fiexit 0# ============================================================= ## Code below will not execute, because the script already exited.# An alternate method of getting to the root of matters:ROOTUSER_NAME=rootusername=`id -nu`              # Or...   username=`whoami`if [ "$username" = "$ROOTUSER_NAME" ]then  echo "Rooty, toot, toot. You are root."else  echo "You are just a regular fella."fi

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?