我正在尝试执行此bash脚本,并试图在其中加入域。
domainjoin-cli
加入$Domain
后,提示输入密码,如果我的密码错误,我希望脚本以msg“ Not Success”退出,如果另一方面是正确的密码,我需要它继续与脚本的其余部分。
#!/bin/bash
echo -n "Domain: "
read Domain
domainjoin-cli join $Domain
if [[ "$password" = 'SUCCESS' ]]
then
echo "SUCCESS"
ls -l
fi
echo
if [[ "$password" = 'Error' ]]
then
echo "Not SUCCESSFULL"
exit
fi
如果我执行脚本,则会收到此错误消息:
3.sh: 5: 3.sh: [[: not found
3.sh: 10: 3.sh: [[: not found
如果密码错误,这是输出:
"Error: LW_ERROR_PASSWORD_MISMATCH [code 0x00009c56] The password is incorrect for the given account"
如果密码正确,这是输出:
"Warning: System restart required Your system has been configured to authenticate to Active Directory for the first time. It is recommended that you restart your system to ensure that all applications recognize the new settings.
SUCCESS"
答案 0 :(得分:2)
-eq
等用于比较数字,因此它将“ SUCCESS”视为数字零,这不是您想要的。< / li>
[[
比[
更可取,因为它很难破解。结果:
[[ "$password" = 'SUCCESS' ]]