让 IPython 脚本检查用户当前是否为根用户的正确方法是什么?
这是我在 bash 脚本中的做法:
if [ $(id -u) != "0" ];then
echo "This script must be run as root."
exit 1
fi
有没有比使用“!id”或“!whoami”更好的方法?
最佳答案
在 *nix 操作系统上有 geteuid()
in the os
module .
关于linux - IPython 检查运行脚本的用户是否是 root 用户 (Linux),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10842132/