两种判断shell执行用户是否为root用户 2018-06-26 成长之路 Linux 约 74 字 预计阅读 1 分钟 次阅读 文章目录 方式一: 1 2 3 4 5 # Check if user is root if [ $(id -u) != "0" ]; then echo "Error: You must be root to run this script, please use root to run" exit 1 fi 方式二: 1 2 # Check if user is root [ $(id -u) != "0" ] && { echo "${CFAILURE}Error: You must be root to run this script${CEND}"; exit 1; } 文章作者 cnbattle 上次更新 2018-06-26 许可协议 CC BY-NC-ND 4.0