|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | 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 Tools | Search this Thread | 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 |
| Sponsored Links | ||
|
|
#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 |
| Sponsored Links | ||
|
|
#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 |
| Sponsored Links | |
|
|
#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 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 |
| Sponsored Links | |
|
|
#6
|
|||
|
|||
|
Thanks I am sorry not to be clear that's for numeric
It worked perfect Thanks for all your help |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| how to write for loop | pdathu | Shell Programming and Scripting | 4 | 10-13-2011 07:46 PM |
| Unable to write to a file within a loop | janardhanamk | UNIX for Dummies Questions & Answers | 1 | 11-15-2010 06:54 AM |
| Push records to array during implicit loop and write to file | jospan | Shell Programming and Scripting | 0 | 01-12-2010 08:06 AM |
| How to write a If loop.. | suri.tyson | Shell Programming and Scripting | 2 | 10-15-2008 10:50 AM |
| trying to write a script to loop through a port info file | rcon1 | Shell Programming and Scripting | 5 | 01-09-2008 05:59 AM |
|
|