LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-24-2011, 01:59 AM   #1
Jerry Mcguire
Member
 
Registered: Jul 2009
Location: Hong Kong SAR
Distribution: RedHat, Fedora
Posts: 201

Rep: Reputation: 31
bash compound tests and parenthesis


In C++ language, we can do the following compound tests,
Code:
std::string a, b, c, d;
if ((a == "Yes" && b == "Yes" ) || (c == "Yes" && d == "Yes")) {
   ...
}
In bash scripts, how can we do the parenthesis around compound tests?

?
Code:
if [ "$a" = "Yes" ] && [ "$b = "Yes" ]   [ "$c" = "Yes" ] && [ "$d" = "Yes" ]; then
   ...
fi
Thanks.
 
Old 03-24-2011, 03:51 AM   #2
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,516

Rep: Reputation: 240Reputation: 240Reputation: 240
try this...
Code:
 [[ "$a" == yes && $b == "yes" ]]
 [[ ("$a" == yes) && ($b == "yes") ]]
man bash
 
Old 03-24-2011, 03:55 AM   #3
Jerry Mcguire
Member
 
Registered: Jul 2009
Location: Hong Kong SAR
Distribution: RedHat, Fedora
Posts: 201

Original Poster
Rep: Reputation: 31
bigearsbilly,

Code:
if [[ ("$a" = "Yes" && "$b" = "Yes") || ("$c" = "Yes" && "$d" = "Yes") ]]; then
   ...
fi
Thanks.

Last edited by Jerry Mcguire; 03-24-2011 at 04:08 AM.
 
Old 03-24-2011, 12:26 PM   #4
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,928

Rep: Reputation: 614Reputation: 614Reputation: 614Reputation: 614Reputation: 614Reputation: 614
Code:
if [ "$a" = "Yes" -a "$b = "Yes" ]  || [ "$c" = "Yes" -a "$d" = "Yes" ]; then
 
Old 03-24-2011, 08:37 PM   #5
Jerry Mcguire
Member
 
Registered: Jul 2009
Location: Hong Kong SAR
Distribution: RedHat, Fedora
Posts: 201

Original Poster
Rep: Reputation: 31
Even better. Thanks all.
 
  


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
[SOLVED] closing parenthesis script cruzdelsur Programming 5 08-30-2010 09:55 AM
Parenthesis and other odd characters passed to bash function jakeo25 Programming 2 04-03-2008 10:27 AM
[SOLVED] shellscript: compound tests (FYI) zedmelon Programming 3 07-19-2006 11:47 AM
vim matching parenthesis rohr Linux - Software 2 04-23-2005 05:12 PM
Can't rename file with parenthesis in name pleasehelp Linux - Newbie 4 03-16-2004 03:01 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:36 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
Open Source Consulting | Domain Registration