The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to write a daemon in Unix? sbasak Shell Programming and Scripting 11 04-23-2008 02:56 AM
How to write CDs/DVDs in SCO Unix aafflatoon SCO 1 01-17-2008 01:24 PM
trying to write a script to loop through a port info file rcon1 Shell Programming and Scripting 5 01-09-2008 03:59 AM
how to write c codes in UNIX rraajjiibb High Level Programming 12 02-01-2006 09:41 PM
Loop through file and write out lines to file(s) Jtrinh Shell Programming and Scripting 7 07-05-2005 12:06 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 07-25-2007
Registered User
 

Join Date: Jul 2007
Posts: 33
How to write if loop in unix

Hi Thanks to one who helped me to create a new thread
I am so new to unix and trying to learn the stuff
Thanks for all the help I am getting here
I wanted to execute if loop like

if( x=y || (x=z && x=q))
{
some statements
}

Can I get help how to do write the if loop in unix shell scripting
I know if it is for two like
if [[ x eq y || x eq z ]] but couldn't do it with the above requirement

Thanks in advance
PINKY
Reply With Quote
Forum Sponsor
  #2  
Old 07-25-2007
Shell_Life's Avatar
Registered User
 

Join Date: Mar 2007
Location: Bahia, Brazil
Posts: 695
Here is one form of looping:
Code:
#!/bin/ksh
typeset -i mCnt=0
while [ ${mCnt} -le 10 ]
do
  echo "Count = "${mCnt}
  mCnt=${mCnt}+1
done
Reply With Quote
  #3  
Old 07-25-2007
DukeNuke2's Avatar
Soulman
 

Join Date: Jul 2006
Location: Germany, Berlin
Posts: 1,468
the syntax depends on the shell you are using...

in the korn shell an if statement looks like:

if [ $a = $b]
then
.....
else
.....
fi
Reply With Quote
  #4  
Old 07-25-2007
Registered User
 

Join Date: Jul 2007
Posts: 33
Unhappy

Thanks for the answers
That didn't help me
I want if statement for exactly this condition
if(x=y || (y=z && a=b))

I was looking to write ksh script

Thanks again
Pinky
Reply With Quote
  #5  
Old 07-25-2007
Shell_Life's Avatar
Registered User
 

Join Date: Mar 2007
Location: Bahia, Brazil
Posts: 695
Pinky,
Your 'if' statement is not clear on to what type the variables x,y,z,a,b are.

It makes a difference if they are string or numeric.

Numeric:
Code:
x=1
y=1
z=3
a=9
b=8
if [ $x -eq $y -o \( $y -eq $z -a $a -eq $b \) ]; then
 echo "FOUND NUMERIC"
else
 echo "NOT FOUND NUMERIC"
fi
Alphanumeric:
Code:
X='A'
Y='A'
Z='C'
A='M'
B='N'
if [ "$X" = "$Y" -o \( "$Y" = "$Z" -a "$A" = "$B" \) ]; then
 echo "FOUND CAPITAL ALPHA"
else
 echo "NOT FOUND CAPITAL ALPHA"
fi
Reply With Quote
  #6  
Old 07-25-2007
Registered User
 

Join Date: Jul 2007
Posts: 33
Thanks I am sorry not to be clear that's for numeric
It worked perfect

Thanks for all your help
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 01:49 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0