如何在msysgit/Cygwin脚本中测试管理员权限?

3
如何在msysgit/Cygwin脚本中测试管理员权限?在我的电脑上,以管理员身份打开Git Bash并运行 whoami 命令仍会输出James而不是root。可能可以尝试以下方式:
if touch /C/file.txt && rm /C/file.txt; then
    echo 'Admin!'
else
    echo 'Not admin!'
fi

但那种方式感觉很粗糙。有没有更好的方法来解决这个问题?
编辑:也尝试了“id”和“id-G”,但对于管理员和普通终端有相同的输出。
1个回答

3

Batch中找到了一个解决方案:

if net session &> /dev/null; then
    echo 'Admin!'
else
    echo 'Not admin!'
fi

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接