LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-20-2008, 12:43 PM   #1
pdklinux79
LQ Newbie
 
Registered: Jun 2008
Posts: 29

Rep: Reputation: 15
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
 
Old 06-20-2008, 01:00 PM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to compare a value p_raju Linux - General 6 05-31-2008 12:03 PM
Case statement with If statement cbo0485 Linux - Newbie 4 11-07-2007 09:05 PM
how to compare munna_dude Programming 10 03-21-2007 08:50 AM
For Statement bendeco13 Linux - General 6 10-31-2004 06:31 PM
If Statement junjem0702 Programming 4 08-23-2004 10:49 AM


All times are GMT -5. The time now is 10:24 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration