当用户未通过身份验证时,pkexec的返回值为126。我怎么使用它?我尝试将pkexec赋值给一个变量以供以后使用,但不起作用。否则,当运行pkexec并且用户进行身份验证时,如何将auth设置为1,以便稍后在脚本中使用它?
我可以使用sudo来避免麻烦(该脚本将chmod /usr/bin/中的一些文件),但我需要该脚本是用户友好的,它将从开始菜单调用,所以我更喜欢pkexec的GUI。
#!/bin/bash
auth=0
pkexec bash -c "[do something as root];auth=1"
if [ $auth = 1 ]; then
[do something]
elif [ $auth = 0 ]; then
[do something else]
fi
# prints 0, not 1, even if the user has authenticated and run pkexec
echo $auth发布于 2021-01-25 16:29:57
根据试探性的建议,这是解决方案:
pkexec bash -c "chmod 000 /usr/bin/mono"
auth=$?
if [ $auth = 0 ]; then
echo ok
elif [ $auth = 126 ]; then
echo sorry
fihttps://stackoverflow.com/questions/65880960
复制相似问题