nested if else -error


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting nested if else -error
# 1  
Old 01-20-2012
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,
Code:
 read var4

everything runs fine. After that the script exits out.
Code:
#!/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
# 2  
Old 01-20-2012
Code:
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.
# 3  
Old 01-20-2012
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.
# 4  
Old 01-20-2012
Did you add all the missing double quotes? not only those mentionned by aigles...
# 5  
Old 01-20-2012
Yes, i have added all missing double quotes. But still no luck
# 6  
Old 01-20-2012
add "set -x" for debuging purposes :
Code:
#!/bin/bash
set -x

Jean-Pierre.
# 7  
Old 01-20-2012
Hi Jean-Pierre,
executed the script as you told, output is,
Code:
+ ./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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Error with nested if within an sqlplus task inside

Hi ALL, I am receving a "strange" error using a nested if within an sql operation inside: ./dom.ksh: syntax error at line 80 : `then' unmatched This is all my script code: in bold the step receiving the error. Any help would really aprrecieted ......! **** I have tried all the... (2 Replies)
Discussion started by: AndreaCecco
2 Replies

2. Shell Programming and Scripting

Nested if else

Hi, i m trying to create script which logic is like below. if ; then x=`cat /tmp/testoutput.log | grep STOP | wc -l` y=`cat /tmp/testoutput.log | grep RUN | wc -l` if ; then echo "process stop" if ; then echo "process running " else echo "file not found" fi ----------------... (2 Replies)
Discussion started by: tapia
2 Replies

3. Shell Programming and Scripting

Mv: cannot access error after nested while loop

I have two methods...create_2_54 and create_2_55 I have added a nested while loop(previously it has just one loop) in create_2_54 the mv command(which comes first in 2_55) is not working. for name in `ls -1 1SMH_WICD_V5_2_5*.txt` ; do mv $name $nametmp.tmp unix2dos -ascii -437 $nametmp.tmp... (2 Replies)
Discussion started by: harish468
2 Replies

4. Shell Programming and Scripting

two while nested loops

for server in $(echo `cat /tmp/ScanHosts_${USERSNAME}.TXT`) do for portnumber in $(echo `cat /tmp/ScanPorts_${USERSNAME}.TXT`) do #echo ${server} ${portnumber} ... (3 Replies)
Discussion started by: SkySmart
3 Replies

5. Shell Programming and Scripting

Intermittent "cp: cannot stat" error with nested loop

I have a bash script that has been running (on SUSE 9.3) dozens of times over the past couple of years without error. Recently it has been hitting intermittent “cp: cannot stat FILE: No such file or directory” errors. The script has nested loops that continuously process files in a... (2 Replies)
Discussion started by: jcart
2 Replies

6. Shell Programming and Scripting

Error while implementing nested if

considering all variables like S01DEPOSITS will return numbers, i am trying to execute below statement if ] then echo "Queue DEP" fi while executing above if statement i am getting error as if : Syntax error at line 100 : `"$1"' is not expected. pls help as soon as possible thanks (3 Replies)
Discussion started by: sagarrd
3 Replies

7. Shell Programming and Scripting

Nested If condition

Hi I have a requirement to create a 2 folder based on there existance if then cd $var_name if then cd $var_name3 mv -fi *.* $var_TargetPath/$var_name/$var_name3 else mkdir -p "$var_name3" chmod 755 "$var_name3" mv -fi *.* $var_TargetPath/$var_name/$var_name3 else mkdir... (7 Replies)
Discussion started by: magesh_bala
7 Replies

8. UNIX for Dummies Questions & Answers

Nested If statement within Do / Done

Hi all! I'm really hoping you can help me out here; now i have searched and searched and have at least worked out that you can't have a nested if statement with a 'done' in it (as i have) as you're killing the parent before the child. So here's what i have, and here's hoping someone can help... (2 Replies)
Discussion started by: dalgibbard
2 Replies

9. UNIX for Dummies Questions & Answers

Nested If question

if ]; then if ]; then rm -f ${LOGFILE}.old fi mv ${LOGFILE} ${LOGFILE}.old fi Havent done nested ifs in a while. I'm reading someones code If I'm reading this correctly. It checks for the logfile, and if it exists it checks for the old logfile and if that exists, it removes the... (8 Replies)
Discussion started by: NycUnxer
8 Replies

10. Shell Programming and Scripting

Nested Arrays

Hi, I'm trying to implement nested arrays in ksh. i've the follwing arrays SRV=\ "SRV1 "\ "SRV2 " SRV1=\ "MD11 "\ "MD12 " SRV2=\ "MD21 "\ "MD22 " MD11=\ "ABC " (5 Replies)
Discussion started by: guysporty
5 Replies
Login or Register to Ask a Question