Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

If statment with or 1

Status
Not open for further replies.

ginger32

Technical User
Feb 17, 2003
6
GB
ok here we go!

I have an if statment with multiple 'or' conditions. The only problem is a can not get my if to see any of the or stantments past the first one!if [ "`logname`%" = "dev3%" or "`logname`%" = "devel1%" or "`logname`%" = "icdevel%" ]
then
if [ `who |grep $LOGNAME |wc -l` -gt 3 ]
then
echo "You will be disconnected due to too many logins plus 3"
sleep 5
exit
fi

the if picks up dev3 but not devel1 or icdevel!



 
Try
if [ "`logname`%" = "dev3%" -o "devel1%" -o "icdevel%" ]
 
Hi,
"-o" is well for integer. For strings you must use "||" for logical OR instead.
Regards Boris





 
Now if always maches the case...

ie

if dev1 logins in he gets 3 logins where all i want is 1 login for dev1
 
This was how i did it!!!
if [ ! "`logname`%" = "devel%" -a ! "`logname`%" = "dev1%" ]
then
if [ "`logname`%" = "dev3%" -o "`logname`%" = "devel1%" -o "`logname`%" = "icdevel%" ]
then
if [ `who |grep $LOGNAME |wc -l` -gt 3 ]
then
echo "You will be disconnected due to too many logins. "
echo "You are allowed to log in 3 times."
sleep 5
exit
fi
else
if [ `who |grep $LOGNAME |wc -l` -gt 1 ]
then
echo "You will be disconnected due to too many logins."
echo "you are allowed 1 login"
sleep 5
exit
fi
fi
fi

 
Hi,

Why not try to solve this with a CASE construction similar to this:

case `logname` in
devel|dev1)
instructions
;;
dev3|devel1|icdevel)
other instructions
;;
esac

Are the % characters to check if the variable exists?

Regards,
Willem
 
the korn shell provides a nice way to do multiple 'or' conditions with an 'if' statement:

if [[ "`logname`%" = @(dev3|devel1|icdevel)% ]] ; then

..do stuff

fi


-jim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top