LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   compare to conditons in while statement (https://www.linuxquestions.org/questions/linux-newbie-8/compare-to-conditons-in-while-statement-650561/)

pdklinux79 06-20-2008 11:43 AM

compare to conditons in while statement
 
this could be simple but yet i need help as different combination of comapring two conditons with while and if didnt work for me in shell

say i need to compare

$hash == '------' or $ hash = 0

how can i do it with IF and WHILE in bash...

eg
if [$hash = '-----' ] or [$hash= 0]
then
..............
else
..................

fi



while [$hash='-------' ] or [$hash = 0 ]
do
...................
done


thanks

colucix 06-20-2008 12:00 PM

Code:

if [ $hash = "------" -o $hash = "0" ]
The logical OR in bash is -o, whereas the logical AND is -a. Also do not confuse arithmetic operators with string operators: EQUAL will be = for string comparison, it will be -eq for integer comparison. See section 7.3 of the Advanced Bash Scripting Guide for details.


All times are GMT -5. The time now is 01:14 PM.