Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在编写一个 BASH 脚本,它以交互方式向用户询问 sudoing 密码。这应该在脚本运行时只发生一次。在继续之前,脚本需要确保密码有效。
验证该密码的最简单方法是什么?
-v
您可以使用 sudo 使用-v标志验证凭据,然后检查 sudo 的退出状态。例如:
if sudo -v; then echo "Exit status: $?" echo "You're validated." else echo "Exit status: $?" echo "You've failed to validate." fi