シェルスクリプトに入れ子になった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