我正在编写一个shell脚本,以简化帐户的htpasswd管理。
我正在尝试检查htpasswd是否使用文档的预期退出状态正确创建。
到目前为止,这就是我所拥有的:
现有的htpasswd:
local _result=$(htpasswd "${HTPASSWD_LOCATION}" "${_htpasswdLogin}")新htpasswd:
local _result=$(htpasswd -c "${HTPASSWD_LOCATION}" "${_htpasswdLogin}")由于某些原因,这是成功的,但我无法捕捉退出状态。
这是我的支票:
if [ "${_result}" = "0" ]; then
echo "User successfully added to the .htpasswd file"
else
echo "Failed to add the user to .htpasswd file"
fi是否有更好的方法来获得退出状态?
发布于 2014-06-02 18:03:32
你可以这样做:
if htpasswd -c "${HTPASSWD_LOCATION}" "${_htpasswdLogin}"; then
echo "User successfully added to the .htpasswd file"
else
echo "Failed to add the user to .htpasswd file"
fihttps://stackoverflow.com/questions/24000565
复制相似问题