检查 root 是否在 bash 脚本中 [英] Checking if root inside bash script

查看:56
本文介绍了检查 root 是否在 bash 脚本中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在运行之前检查运行脚本的用户是否是root用户.但它似乎不起作用.我目前以 root 身份登录,但我认为语法有问题.

I want to check if the user running the script is root or not before running. But it doesn't seem to work. I'm currently logged in as root, but its something wrong with the syntax I think.

if[[ $EUID -ne 0 ]];
then
 echo "Sorry, you are not root."
 exit 1
else
 echo "You are root, script will continue."
fi

推荐答案

if[ 之间需要一个空格.

You need a space between if and [.

这篇关于检查 root 是否在 bash 脚本中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆