You are not logged in.

#1 2009-06-18 22:35:07

brando56894
Member
From: NYC
Registered: 2008-08-03
Posts: 681

[Solved] IF statement is confusing me

Im testing out a bit of code to put in my arch stage 2 installation script and it works but in the exact opposite way that I want it to and I cant figure out the logic behind it, can someone clue me in?

#! /bin/bash

ls -a /home/bran | grep thunderbird

if [ -d /home/bran/.thunderbird ]; then
    echo "removing thunderbird directory"
    sudo rm -rf /home/bran/.thunderbird
fi

ls -a /home/bran | grep thunderbird
ln -s /media/w7/Users/bran/AppData/Roaming/Thunderbird/qmu8f6lc.default /home/bran/.thunderbird

gives the output of:
.thunderbird
.thunderbird
ln: creating symbolic link `/home/bran/.thunderbird': File exists


while if I change the if statement to this: if [ ! -d /home/bran/.thunderbird ]; then

this is the output that I get:
.thunderbird
removing thunderbird directory

which is the way I want the script to work. So my question is why does the script successfully enter the if statement when I tell it to remove the directory if the directory doesnt exist even though it does actually exist?? Its confusing the hell out of me...

Last edited by brando56894 (2009-06-19 01:30:58)

Offline

#2 2009-06-18 23:01:54

TheBodziO
Member
From: Dukla, Poland
Registered: 2006-07-28
Posts: 230
Website

Re: [Solved] IF statement is confusing me

It appears that in your case ".thunderbird" is a _file_ (check in "long" format of "ls").

Last edited by TheBodziO (2009-06-18 23:03:14)


It's not the best thing when they call you a "member" you know… wink

Offline

#3 2009-06-18 23:38:03

arkham
Member
From: Stockholm
Registered: 2008-10-26
Posts: 516
Website

Re: [Solved] IF statement is confusing me

Use

if [ -e /home/bran/.thunderbird ]; then

Last edited by arkham (2009-06-18 23:38:24)


"I'm Winston Wolfe. I solve problems."

~ Need moar games? [arch-games] ~ [aurcheck] AUR haz updates? ~

Offline

#4 2009-06-19 00:17:47

brando56894
Member
From: NYC
Registered: 2008-08-03
Posts: 681

Re: [Solved] IF statement is confusing me

@ thebodzio: nope its a hidden directory for thunderbird that stores all your profile info

@ arkham: I had tried that before and it didnt work, just for the hell of it I tried it again and it worked... odd. why wouldnt the -d flag work considering it is an actual directory?

Offline

#5 2009-06-19 00:38:21

TheBodziO
Member
From: Dukla, Poland
Registered: 2006-07-28
Posts: 230
Website

Re: [Solved] IF statement is confusing me

Don't get me wrong but… could you check

ls -ld .thunderbird

Last edited by TheBodziO (2009-06-19 00:40:04)


It's not the best thing when they call you a "member" you know… wink

Offline

#6 2009-06-19 01:18:08

brando56894
Member
From: NYC
Registered: 2008-08-03
Posts: 681

Re: [Solved] IF statement is confusing me

[bran@ra ~]$ ls -ld .thunderbird
drwxr-xr-x 2 bran bran 4096 2009-06-17 21:17 .thunderbird

edit: it works now, thanks for the help

Last edited by brando56894 (2009-06-19 01:30:44)

Offline

#7 2009-06-19 06:51:32

TheBodziO
Member
From: Dukla, Poland
Registered: 2006-07-28
Posts: 230
Website

Re: [Solved] IF statement is confusing me

Thanks for the reply! I suspect that it wasn't a directory when "things wasn't working" but hey… who knows wink. I'm happy that it works for you now! big_smile


It's not the best thing when they call you a "member" you know… wink

Offline

Board footer

Powered by FluxBB