nested if else -error

HI everyone,

I am not able to find error in the script, when i run the script till
line No. 20
i.e,

 read var4

everything runs fine. After that the script exits out.

#!/bin/bash

echo -e "Want dryrun OR merge: \n "
read var1

if [[ "$var1" != dryrun && "$var1" != merge ]] ; then
echo -e "\n  Please select from the given option \n"
exit
fi

echo -e " Give me the release.bom file URL \n"
read var2
wget --no-check-certificate --user=USER --password=Password $var2

IFS=/ read -a ARRAY <<< "$var2"
var3="${ARRAY[7]}"

echo -e " \n You want only Projects branched out to $var3 OR the whole branch merge \n "
read var4

if [ $var4 == $var3 ] ;
    if [ $var1 = dryrun ] ; then
        sed -n '/$var3/p' < release.bom | awk '{print $2;}' | sed -n 's/https/svn merge -r xxxx:HEAD https/g' | sed -n 's/$var3/$var3 --dry-run/g'
    elif [ $var1 = merge ] ; then
        sed -n '/$var3/p' < release.bom | awk '{print $2;}' | sed -n 's/https/svn merge -r xxxx:HEAD https/g'
    fi
else
    if [ $var1 = dryrun ] ; then
        awk '{print $2;}' < release.bom | sed 's/https/svn merge -r xxxx:HEAD https/g' 
    elif [ $var1 = merge ] ; then
        awk '{print $2;}' < release.bom | sed 's/https/svn merge -r xxxx:HEAD https/g'
    fi
fi

Thanks,
Rishi

echo -e " \n You want only Projects branched out to $var3 OR the whole branch merge \n "
read var4

if [ "$var4" == "$var3" ] ; then
    if [ "$var1" = dryrun ] ; then
        sed -n '/$var3/p' < release.bom | awk '{print $2;}' | sed -n 's/https/svn merge -r xxxx:HEAD https/g' | sed -n 's/$var3/$var3 --dry-run/g'

Jean-Pierre.

Hi Aigles,

Thanks for the quick reply. I added all the changes you mentioned.
But, its not working, still the same problem, script exits after line no 20.

Did you add all the missing double quotes? not only those mentionned by aigles...

Yes, i have added all missing double quotes. But still no luck

add "set -x" for debuging purposes :

#!/bin/bash
set -x

Jean-Pierre.

Hi Jean-Pierre,
executed the script as you told, output is,

+ ./test.sh
+ echo -e 'Want dryrun OR merge: \n '
Want dryrun OR merge: 
 
+ read var1
dryrun
+ [[ dryrun != dryrun ]]
+ echo -e ' Give me the release.bom file URL \n'
 Give me the release.bom file URL 

+ read var2
https://svn.xxxx.com/repos/xx/Releases/Delivery/Project13/release.bom
+ wget --no-check-certificate --user=USER --password=Password https://svn.xxxx.com/repos/xx/Releases/Delivery/Project13/release.bom
--07:05:38--  https://svn.xxxx.com/repos/xx/Releases/Delivery/Project13/release.bom
Resolving svn.xxxx.com... x.x.x.x
Connecting to svn.xxxx.com|x.x.x.x|:443... connected.
WARNING: Certificate verification error for svn.xxxx.com: unable to get local issuer certificate
HTTP request sent, awaiting response... 
coppied => `release.bom.'
+ IFS=/
+ read -a ARRAY
+ var3=Project13
+ echo -e ' \n You want only Projects branched out to Project13 OR the whole branch merge \n '
 
 You want only Projects branched out to Project13 OR the whole branch merge 
 
+ read var4
Project13
+ '[' Project13 == Project13 ']'
+ '[' dryrun = dryrun ']'
+ sed -n '/$var3/p'
+ awk '{print $2;}'
+ sed -n 's/https/svn merge -r xxxx:HEAD https/g'
+ sed -n 's/$var3/$var3 --dry-run/g'

Thanks,
Rishi

No errors... it ended normally...
What were you expecting?

Hi vbe,
It has to exicute these commands right ?

 
+ read var4
Project13
+ '[' Project13 == Project13 ']'
+ '[' dryrun = dryrun ']'
+ sed -n '/$var3/p'
+ awk '{print $2;}'
+ sed -n 's/https/svn merge -r xxxx:HEAD https/g'
+ sed -n 's/$var3/$var3 --dry-run/g'

Please let me know what to add in script to execute the above command if

 + '[' Project13 == Project13 ']'
+ '[' dryrun = dryrun ']'

---------- Post updated at 03:13 AM ---------- Previous update was at 02:08 AM ----------

If script is working fine, then why sed and awk command not executing......
Any suggestions would be very helpful.

Rishi

sed -n 's/$var3/$var3 --dry-run/g'

did not go under variable interpolation, is that what you mean by "not executing"?? In that case you'll have to use " instead of ' for your sed script.

1 Like

That's the exact problem. And i didn't get you

you'll have to use " instead of ' for your sed script.

---------- Post updated at 04:51 AM ---------- Previous update was at 04:48 AM ----------

I got it. I have to use double quotes instead of single quote.

Thanks, its working now :slight_smile: