首页 > 解决方案 > 尝试在 if 中添加两个条件

问题描述

我正在尝试执行这个 bash 脚本,我正在尝试加入域。

domainjoin-cli加入后$Domain它会提示输入密码,如果我的密码错误,我希望脚本退出并显示一条消息“不成功”,如果另一方面它是正确的密码,我需要它来继续脚本的其余部分。

#!/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"

标签: bash

解决方案



推荐阅读