![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| 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 !! |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
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 |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
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
|
|
#3
|
||||
|
||||
|
the syntax depends on the shell you are using...
in the korn shell an if statement looks like: if [ $a = $b] then ..... else ..... fi |
|
#4
|
|||
|
|||
|
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 |
|
#5
|
||||
|
||||
|
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 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 |
|
#6
|
|||
|
|||
|
Thanks I am sorry not to be clear that's for numeric
It worked perfect Thanks for all your help |
|||
| Google The UNIX and Linux Forums |