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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

While Loop

Status
Not open for further replies.

mosama1

Technical User
Apr 23, 2008
7
0
0
EG
I want ti know if this script is true or not

while [ $RET -ne 0 || $RET -ne 3 ];
do
RET=$?
done

 
Did you assign a value to $RET before running this piece of code?
If the answer is no, then your code is the same as:

while [ -ne 0 || -ne 3 ];
do
RET=$?
done

And that's a syntax error obviously.
 
Hi

Code:
while [ $RET -ne 0 [red]||[/red] $RET -ne 3 ][red];[/red]
do
    RET=$?
done
[tt][red]||[/red][/tt] - wrong, use [tt]-o[/tt] instead
[tt][red];[/red][/tt] - wrong, not needed
Beside this, the [tt]while[/tt] is pointless, an [tt]if[/tt] would be enough. ( Unless you really want to run into an endless loop. )

Feherke.
 
Yes the value of $RET is assigned i ask about this line of code

while [ $RET -ne 0 || $RET -ne 3 ];

is true
 
man test

Furthermore, ANY value of $RET is either different from 0 or different from 3, so the logic seems broken ...

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
what is the different between || and -o
 
Again, man test

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I agree with PHV, the logic is broken. It should be a logical "and", not a logical "or".

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top