嵌套if语句执行错误

嵌套if语句执行错误

我正在尝试在 shell 脚本中编写嵌套 if 语句。脚本如下。

#select the snapshot or release    
if  [ "$SELECT_SNAP_OR_REL_VERSION" == "Snapshots" ]
then
    $SELECT_SNAPSHOT_VERSION
    echo "Snapshot Selected"

elif [ "$SELECT_SNAP_OR_REL_VERSION" == "Releases" ] 
then
     $SELECT_RELEASE_VERSION
     echo "Release Selected"

     if [ "$Server_Selection" == "192.168.94.139" ]
     then
         selectDevSnap;
         echo "deployed to 139"

     elif [ "$Server_Selection" == "192.168.94.140" ]
     then
         selectProdRel
         echo "deployed to 140"

      else 
          echo "ERROR"

      fi

else 
      echo "Error Selection"
fi

在此脚本中仅执行“192.168.94.140”部分。我该如何纠正这个问题?

答案1

这对我有用。

relVersion="$SELECT_RELEASE_VERSION_ARTIFACT_URL" 

snapVersion="$SELECT_SNAPSHOT_VERSION_ARTIFACT_URL"         

source=(/var/lib/jenkins/workspace/Proj_Frontend_Parameterized_Deployment/*.tgz) 

selectDevSnap(){

           devDestination=([email protected]:/usr/share/nginx/PROJFRONTEND/proj.com/)

           wget "$snapVersion"
           scp $source $devDestination
           ssh [email protected] "cd /usr/share/nginx/PROJFRONTEND/proj.com/ ; tar xvf *.tgz"

            }


selectProdRel(){

           prodDestination=([email protected]:/usr/share/nginx/PROJFRONTEND/proj.com/)

           wget "$relVersion"
           scp $source $prodDestination
           ssh [email protected] "cd /usr/share/nginx/PROJFRONTEND/proj.com/ ; tar xvf *.tgz"

            }

             if  [ "$SELECT_SNAP_OR_REL_VERSION" == "Snapshots" ]
            then
                   $SELECT_SNAPSHOT_VERSION
                   echo "Snapshot Selected"

                if [ "$SELECT_SNAP_OR_REL_VERSION" == "Releases" ] 
                then
                   $SELECT_RELEASE_VERSION
                   echo "Release Selected"
                fi

                if [ "$Server_Selection" == "192.168.94.139" ]
                then
                    selectDevSnap;
                    echo "deployed to 139"

                elif [ "$Server_Selection" == "192.168.94.140" ]
                then
                   selectProdRel
                   echo "deployed to 140"

                else 
                   echo "ERROR"

                fi

            else 
                echo "Error Selection"

            fi

相关内容