Operating System - HP-UX
1833785 Members
2800 Online
110063 Solutions
New Discussion

problem with validation in a IF

 
SOLVED
Go to solution
Patrice Blanchard_2
Frequent Advisor

problem with validation in a IF

Hi,

i'm trying to validate a login in a IF statement but it's not working. What i'm doing is:

user_id=`whoami`

if [$user_id = "bsp" ]
elist=bsp@domain.com
fi

i've tried single quotes, double quotes and no quotes but it does not work.

I know that user_id=`whoami` works and that if i do elist=`whoami`@domain.com works also, the only thing i want to validate is if user_id = bsp

I know that it's probably a stupid syntax error that i'm doing but can't see what.

regards

PB
4 REPLIES 4
Mark Grant
Honored Contributor
Solution

Re: problem with validation in a IF

You need a space between the [ and the $user_id
Never preceed any demonstration with anything more predictive than "watch this"
Patrice Blanchard_2
Frequent Advisor

Re: problem with validation in a IF

Hi,

it didn't do anything.

I did:

if [ $user_id="bsp" ]
elist=bsp@domain.com
fi

regards

PB
Mark Grant
Honored Contributor

Re: problem with validation in a IF

If it didn't do anything then I would guess that the user id is not "bsp".

Maybe you have the wrong ` marks around your whoami command. Try the less confusing

user_id=$(whoami)

If not do this

user_id=$(whoami)

echo "user id is $userid"

if [ $user_id = "bsp" ]
then ### OOPS, you missed out this bit too
elist=bsp@domain
fi

echo "elist is $elist"



Never preceed any demonstration with anything more predictive than "watch this"
Patrice Blanchard_2
Frequent Advisor

Re: problem with validation in a IF

worked.
Thanks