Nested if statement execution error [duplicate]











up vote
-1
down vote

favorite













This question is an exact duplicate of:




  • Combine if statements [on hold]



I am trying to write a nested-if statement in shell script. Script is given below.



#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


In this script only execute "192.168.94.140" section. How can I correct this?










share|improve this question















marked as duplicate by RalfFriedl, elbarna, muru, Kusalananda, roaima 2 days ago


This question was marked as an exact duplicate of an existing question.















  • Try set -x to see what happens.
    – RalfFriedl
    2 days ago










  • Why did you start another question for unix.stackexchange.com/questions/483119/… ?
    – RalfFriedl
    2 days ago










  • What are the values of the involved variables?
    – Kusalananda
    2 days ago










  • @RalfFriedl Previously I did'nt have an idea how to combine those two scripts. But I tried and got an answer, in here I got an error in the script.
    – Janith
    2 days ago















up vote
-1
down vote

favorite













This question is an exact duplicate of:




  • Combine if statements [on hold]



I am trying to write a nested-if statement in shell script. Script is given below.



#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


In this script only execute "192.168.94.140" section. How can I correct this?










share|improve this question















marked as duplicate by RalfFriedl, elbarna, muru, Kusalananda, roaima 2 days ago


This question was marked as an exact duplicate of an existing question.















  • Try set -x to see what happens.
    – RalfFriedl
    2 days ago










  • Why did you start another question for unix.stackexchange.com/questions/483119/… ?
    – RalfFriedl
    2 days ago










  • What are the values of the involved variables?
    – Kusalananda
    2 days ago










  • @RalfFriedl Previously I did'nt have an idea how to combine those two scripts. But I tried and got an answer, in here I got an error in the script.
    – Janith
    2 days ago













up vote
-1
down vote

favorite









up vote
-1
down vote

favorite












This question is an exact duplicate of:




  • Combine if statements [on hold]



I am trying to write a nested-if statement in shell script. Script is given below.



#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


In this script only execute "192.168.94.140" section. How can I correct this?










share|improve this question
















This question is an exact duplicate of:




  • Combine if statements [on hold]



I am trying to write a nested-if statement in shell script. Script is given below.



#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


In this script only execute "192.168.94.140" section. How can I correct this?





This question is an exact duplicate of:




  • Combine if statements [on hold]







linux bash shell






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 2 days ago









Rui F Ribeiro

38.2k1475125




38.2k1475125










asked 2 days ago









Janith

12




12




marked as duplicate by RalfFriedl, elbarna, muru, Kusalananda, roaima 2 days ago


This question was marked as an exact duplicate of an existing question.






marked as duplicate by RalfFriedl, elbarna, muru, Kusalananda, roaima 2 days ago


This question was marked as an exact duplicate of an existing question.














  • Try set -x to see what happens.
    – RalfFriedl
    2 days ago










  • Why did you start another question for unix.stackexchange.com/questions/483119/… ?
    – RalfFriedl
    2 days ago










  • What are the values of the involved variables?
    – Kusalananda
    2 days ago










  • @RalfFriedl Previously I did'nt have an idea how to combine those two scripts. But I tried and got an answer, in here I got an error in the script.
    – Janith
    2 days ago


















  • Try set -x to see what happens.
    – RalfFriedl
    2 days ago










  • Why did you start another question for unix.stackexchange.com/questions/483119/… ?
    – RalfFriedl
    2 days ago










  • What are the values of the involved variables?
    – Kusalananda
    2 days ago










  • @RalfFriedl Previously I did'nt have an idea how to combine those two scripts. But I tried and got an answer, in here I got an error in the script.
    – Janith
    2 days ago
















Try set -x to see what happens.
– RalfFriedl
2 days ago




Try set -x to see what happens.
– RalfFriedl
2 days ago












Why did you start another question for unix.stackexchange.com/questions/483119/… ?
– RalfFriedl
2 days ago




Why did you start another question for unix.stackexchange.com/questions/483119/… ?
– RalfFriedl
2 days ago












What are the values of the involved variables?
– Kusalananda
2 days ago




What are the values of the involved variables?
– Kusalananda
2 days ago












@RalfFriedl Previously I did'nt have an idea how to combine those two scripts. But I tried and got an answer, in here I got an error in the script.
– Janith
2 days ago




@RalfFriedl Previously I did'nt have an idea how to combine those two scripts. But I tried and got an answer, in here I got an error in the script.
– Janith
2 days ago










1 Answer
1






active

oldest

votes

















up vote
0
down vote













This works for me.



relVersion="$SELECT_RELEASE_VERSION_ARTIFACT_URL" 

snapVersion="$SELECT_SNAPSHOT_VERSION_ARTIFACT_URL"

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

selectDevSnap(){

devDestination=(proj@192.168.94.139:/usr/share/nginx/PROJFRONTEND/proj.com/)

wget "$snapVersion"
scp $source $devDestination
ssh proj@192.168.94.139 "cd /usr/share/nginx/PROJFRONTEND/proj.com/ ; tar xvf *.tgz"

}


selectProdRel(){

prodDestination=(proj@192.168.94.140:/usr/share/nginx/PROJFRONTEND/proj.com/)

wget "$relVersion"
scp $source $prodDestination
ssh proj@192.168.94.140 "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





share|improve this answer























  • Sure, but we still don't know what $SELECT_RELEASE_VERSION is (it's treated as code here), or what any of the other variables are. It's hard to debug a program when you don't know what it looks like and under what data it takes to reproduce the bug.
    – Kusalananda
    2 days ago












  • Yeah, But I am working on Jenkins Deployment Project. $SELECT_RELEASE_VERSION is the variable I assigned into a plugin
    – Janith
    2 days ago


















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote













This works for me.



relVersion="$SELECT_RELEASE_VERSION_ARTIFACT_URL" 

snapVersion="$SELECT_SNAPSHOT_VERSION_ARTIFACT_URL"

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

selectDevSnap(){

devDestination=(proj@192.168.94.139:/usr/share/nginx/PROJFRONTEND/proj.com/)

wget "$snapVersion"
scp $source $devDestination
ssh proj@192.168.94.139 "cd /usr/share/nginx/PROJFRONTEND/proj.com/ ; tar xvf *.tgz"

}


selectProdRel(){

prodDestination=(proj@192.168.94.140:/usr/share/nginx/PROJFRONTEND/proj.com/)

wget "$relVersion"
scp $source $prodDestination
ssh proj@192.168.94.140 "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





share|improve this answer























  • Sure, but we still don't know what $SELECT_RELEASE_VERSION is (it's treated as code here), or what any of the other variables are. It's hard to debug a program when you don't know what it looks like and under what data it takes to reproduce the bug.
    – Kusalananda
    2 days ago












  • Yeah, But I am working on Jenkins Deployment Project. $SELECT_RELEASE_VERSION is the variable I assigned into a plugin
    – Janith
    2 days ago















up vote
0
down vote













This works for me.



relVersion="$SELECT_RELEASE_VERSION_ARTIFACT_URL" 

snapVersion="$SELECT_SNAPSHOT_VERSION_ARTIFACT_URL"

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

selectDevSnap(){

devDestination=(proj@192.168.94.139:/usr/share/nginx/PROJFRONTEND/proj.com/)

wget "$snapVersion"
scp $source $devDestination
ssh proj@192.168.94.139 "cd /usr/share/nginx/PROJFRONTEND/proj.com/ ; tar xvf *.tgz"

}


selectProdRel(){

prodDestination=(proj@192.168.94.140:/usr/share/nginx/PROJFRONTEND/proj.com/)

wget "$relVersion"
scp $source $prodDestination
ssh proj@192.168.94.140 "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





share|improve this answer























  • Sure, but we still don't know what $SELECT_RELEASE_VERSION is (it's treated as code here), or what any of the other variables are. It's hard to debug a program when you don't know what it looks like and under what data it takes to reproduce the bug.
    – Kusalananda
    2 days ago












  • Yeah, But I am working on Jenkins Deployment Project. $SELECT_RELEASE_VERSION is the variable I assigned into a plugin
    – Janith
    2 days ago













up vote
0
down vote










up vote
0
down vote









This works for me.



relVersion="$SELECT_RELEASE_VERSION_ARTIFACT_URL" 

snapVersion="$SELECT_SNAPSHOT_VERSION_ARTIFACT_URL"

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

selectDevSnap(){

devDestination=(proj@192.168.94.139:/usr/share/nginx/PROJFRONTEND/proj.com/)

wget "$snapVersion"
scp $source $devDestination
ssh proj@192.168.94.139 "cd /usr/share/nginx/PROJFRONTEND/proj.com/ ; tar xvf *.tgz"

}


selectProdRel(){

prodDestination=(proj@192.168.94.140:/usr/share/nginx/PROJFRONTEND/proj.com/)

wget "$relVersion"
scp $source $prodDestination
ssh proj@192.168.94.140 "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





share|improve this answer














This works for me.



relVersion="$SELECT_RELEASE_VERSION_ARTIFACT_URL" 

snapVersion="$SELECT_SNAPSHOT_VERSION_ARTIFACT_URL"

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

selectDevSnap(){

devDestination=(proj@192.168.94.139:/usr/share/nginx/PROJFRONTEND/proj.com/)

wget "$snapVersion"
scp $source $devDestination
ssh proj@192.168.94.139 "cd /usr/share/nginx/PROJFRONTEND/proj.com/ ; tar xvf *.tgz"

}


selectProdRel(){

prodDestination=(proj@192.168.94.140:/usr/share/nginx/PROJFRONTEND/proj.com/)

wget "$relVersion"
scp $source $prodDestination
ssh proj@192.168.94.140 "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






share|improve this answer














share|improve this answer



share|improve this answer








edited 2 days ago

























answered 2 days ago









Janith

12




12












  • Sure, but we still don't know what $SELECT_RELEASE_VERSION is (it's treated as code here), or what any of the other variables are. It's hard to debug a program when you don't know what it looks like and under what data it takes to reproduce the bug.
    – Kusalananda
    2 days ago












  • Yeah, But I am working on Jenkins Deployment Project. $SELECT_RELEASE_VERSION is the variable I assigned into a plugin
    – Janith
    2 days ago


















  • Sure, but we still don't know what $SELECT_RELEASE_VERSION is (it's treated as code here), or what any of the other variables are. It's hard to debug a program when you don't know what it looks like and under what data it takes to reproduce the bug.
    – Kusalananda
    2 days ago












  • Yeah, But I am working on Jenkins Deployment Project. $SELECT_RELEASE_VERSION is the variable I assigned into a plugin
    – Janith
    2 days ago
















Sure, but we still don't know what $SELECT_RELEASE_VERSION is (it's treated as code here), or what any of the other variables are. It's hard to debug a program when you don't know what it looks like and under what data it takes to reproduce the bug.
– Kusalananda
2 days ago






Sure, but we still don't know what $SELECT_RELEASE_VERSION is (it's treated as code here), or what any of the other variables are. It's hard to debug a program when you don't know what it looks like and under what data it takes to reproduce the bug.
– Kusalananda
2 days ago














Yeah, But I am working on Jenkins Deployment Project. $SELECT_RELEASE_VERSION is the variable I assigned into a plugin
– Janith
2 days ago




Yeah, But I am working on Jenkins Deployment Project. $SELECT_RELEASE_VERSION is the variable I assigned into a plugin
– Janith
2 days ago



Popular posts from this blog

Accessing regular linux commands in Huawei's Dopra Linux

Can't connect RFCOMM socket: Host is down

Kernel panic - not syncing: Fatal Exception in Interrupt