如何测试您是否在 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
,但它们对管理终端和常规终端的输出相同。
最佳答案
从Batch找到解决方案:
if net session &> /dev/null; then
echo 'Admin!'
else
echo 'Not admin!'
fi
关于windows - 如何在 msysgit/Cygwin 脚本中测试管理员权限?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34497888/