Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 07-29-2010, 05:54 AM   #1
LQ Newbie
Registered: Jul 2010
Posts: 8

Rep: Reputation: 0
If Condition with logical AND

I have got 6 strings:
parentFName, parentLName, parentPostcode
nextFName, nextLName, nextPostcode

In my If Condition, I would like to test if:
(parentFName equals nextFName) & (parentLName equals nextLName) & (parentPostcode equals nextPostcode)

Currently, I have this as my IF Condition but it does not work (it evaluates to false wrongly):

if [ \( \( "$parentFName" = "$nextFName" \) -a \( "$parentLName" = "$nextLName" \) \) -a \( "$parentPostcode" = "$nextPostcode" \) ]
then echo matches
else echo does not match

One more question: is it the backslash (\) that I use to continue on the next line if my command is too long?

Any help, would be greatly appreciated.
Old 07-29-2010, 06:08 AM   #2
Gentoo support team
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,077

Rep: Reputation: 400Reputation: 400Reputation: 400Reputation: 400Reputation: 400
We have no idea what language are you speaking about. Because of the backslash thing and some syntactic elements I infer that it's some kind of shell scripting language. In bash, you would do:

if [ "$foo" = "1" ] && [ "$bar" = "2" ]; then echo we have a match; fi
And yes, the backslash can be used to escape the end of line so it doesn't get interpreted by your shell (and hence, the command continues on the next line).

Details might vary depending on the concrete shell language you use.
Old 07-29-2010, 06:17 AM   #3
LQ Newbie
Registered: Jul 2010
Posts: 8

Original Poster
Rep: Reputation: 0
Thanks i92guboj

I was indeed referring to bash in my post earlier.

You have cleaned up the confusion. Thanks again.


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
Extending logical volume LogVol01 Insufficient allocatable logical exte swap space umeshsharma Linux - Newbie 4 06-22-2009 12:26 PM
How to get the ID of a window according to some particular condition? julianLiuRsch Programming 3 12-01-2008 03:53 AM
if condition furqan_sindhu Linux - Newbie 5 09-22-2007 06:56 AM
using OR condition in if condition Fond_of_Opensource Linux - Newbie 2 10-20-2006 12:34 AM
preg not condition dlublink Programming 5 05-31-2006 12:39 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:47 PM.

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