<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: Multiple expression if statement in BASH</title>
	<atom:link href="http://crazedmonkey.com/blog/programming/multiple-expression-if-statement-in-bash.html/feed" rel="self" type="application/rss+xml" />
	<link>http://crazedmonkey.com/blog/programming/multiple-expression-if-statement-in-bash.html</link>
	<description>Ian Stevens' weblog</description>
	<pubDate>Mon, 08 Sep 2008 06:53:52 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5</generator>
		<item>
		<title>By: stef</title>
		<link>http://crazedmonkey.com/blog/programming/multiple-expression-if-statement-in-bash.html#comment-57211</link>
		<dc:creator>stef</dc:creator>
		<pubDate>Tue, 12 Aug 2008 12:21:54 +0000</pubDate>
		<guid isPermaLink="false">http://crazedmonkey.com/blog/programming/multiple-expression-if-statement-in-bash.html#comment-57211</guid>
		<description>I concur, the logical AND always has precedence before the logical OR. Basic math logic that you learn in high school 4th year i think.

See ya!</description>
		<content:encoded><![CDATA[<p>I concur, the logical AND always has precedence before the logical OR. Basic math logic that you learn in high school 4th year i think.</p>
<p>See ya!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rechosen</title>
		<link>http://crazedmonkey.com/blog/programming/multiple-expression-if-statement-in-bash.html#comment-56677</link>
		<dc:creator>Rechosen</dc:creator>
		<pubDate>Wed, 06 Aug 2008 16:41:26 +0000</pubDate>
		<guid isPermaLink="false">http://crazedmonkey.com/blog/programming/multiple-expression-if-statement-in-bash.html#comment-56677</guid>
		<description>According to tldp.org, the -a (for and) operator has precedence over -o (for or), which means that -a is evaluated and processed before -o. The following experiment shows it:

foo=1
bar=2

if [ $foo -eq 2 -a $bar -eq 2 -o $bar -eq 1 ]; then
        echo "Or has precedence."
else
        echo "And has precedence."
fi

The above returns "And has precedence."</description>
		<content:encoded><![CDATA[<p>According to tldp.org, the -a (for and) operator has precedence over -o (for or), which means that -a is evaluated and processed before -o. The following experiment shows it:</p>
<p>foo=1<br />
bar=2</p>
<p>if [ $foo -eq 2 -a $bar -eq 2 -o $bar -eq 1 ]; then<br />
        echo &#8220;Or has precedence.&#8221;<br />
else<br />
        echo &#8220;And has precedence.&#8221;<br />
fi</p>
<p>The above returns &#8220;And has precedence.&#8221;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tony</title>
		<link>http://crazedmonkey.com/blog/programming/multiple-expression-if-statement-in-bash.html#comment-56559</link>
		<dc:creator>Tony</dc:creator>
		<pubDate>Tue, 05 Aug 2008 17:23:35 +0000</pubDate>
		<guid isPermaLink="false">http://crazedmonkey.com/blog/programming/multiple-expression-if-statement-in-bash.html#comment-56559</guid>
		<description>Great help Ian!

Another evaluation that might be hepful...
Let say you supposed to have two environment variables $A and $B(A and B could be files as well), you want to know if those values are set or not, you can use
if [ -z $A -a -z $B ];
then
  echo "Please define A and B"
fi

this is useful when you have many conditions to evaluate</description>
		<content:encoded><![CDATA[<p>Great help Ian!</p>
<p>Another evaluation that might be hepful&#8230;<br />
Let say you supposed to have two environment variables $A and $B(A and B could be files as well), you want to know if those values are set or not, you can use<br />
if [ -z $A -a -z $B ];<br />
then<br />
  echo &#8220;Please define A and B&#8221;<br />
fi</p>
<p>this is useful when you have many conditions to evaluate</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ian Stevens</title>
		<link>http://crazedmonkey.com/blog/programming/multiple-expression-if-statement-in-bash.html#comment-38181</link>
		<dc:creator>Ian Stevens</dc:creator>
		<pubDate>Tue, 26 Feb 2008 03:54:54 +0000</pubDate>
		<guid isPermaLink="false">http://crazedmonkey.com/blog/programming/multiple-expression-if-statement-in-bash.html#comment-38181</guid>
		<description>In this case, both $bar and $abc must be 1, regardless of the value of $foo.</description>
		<content:encoded><![CDATA[<p>In this case, both $bar and $abc must be 1, regardless of the value of $foo.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David</title>
		<link>http://crazedmonkey.com/blog/programming/multiple-expression-if-statement-in-bash.html#comment-38136</link>
		<dc:creator>David</dc:creator>
		<pubDate>Mon, 25 Feb 2008 19:13:25 +0000</pubDate>
		<guid isPermaLink="false">http://crazedmonkey.com/blog/programming/multiple-expression-if-statement-in-bash.html#comment-38136</guid>
		<description>You can intermix the two, but how does it flow?  IOW, if I say
if [ $foo -eq 1 -o $bar -eq 1 -a $abc -eq 1 ]
does that mean that either $foo or $bar can be 1 but $abc must be 1?  Or does it mean that either $foo can be 1 or $bar and $abc can be 1?</description>
		<content:encoded><![CDATA[<p>You can intermix the two, but how does it flow?  IOW, if I say<br />
if [ $foo -eq 1 -o $bar -eq 1 -a $abc -eq 1 ]<br />
does that mean that either $foo or $bar can be 1 but $abc must be 1?  Or does it mean that either $foo can be 1 or $bar and $abc can be 1?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: dave</title>
		<link>http://crazedmonkey.com/blog/programming/multiple-expression-if-statement-in-bash.html#comment-32636</link>
		<dc:creator>dave</dc:creator>
		<pubDate>Wed, 23 Jan 2008 01:38:20 +0000</pubDate>
		<guid isPermaLink="false">http://crazedmonkey.com/blog/programming/multiple-expression-if-statement-in-bash.html#comment-32636</guid>
		<description>Thanks helped me solve my &#38;&#38; &#124;&#124; bools</description>
		<content:encoded><![CDATA[<p>Thanks helped me solve my &amp;&amp; || bools</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: simon</title>
		<link>http://crazedmonkey.com/blog/programming/multiple-expression-if-statement-in-bash.html#comment-31495</link>
		<dc:creator>simon</dc:creator>
		<pubDate>Sat, 12 Jan 2008 17:52:31 +0000</pubDate>
		<guid isPermaLink="false">http://crazedmonkey.com/blog/programming/multiple-expression-if-statement-in-bash.html#comment-31495</guid>
		<description>Quite useful since I googled "bash if" and your explanation was exactly what I needed!</description>
		<content:encoded><![CDATA[<p>Quite useful since I googled &#8220;bash if&#8221; and your explanation was exactly what I needed!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Durand</title>
		<link>http://crazedmonkey.com/blog/programming/multiple-expression-if-statement-in-bash.html#comment-27960</link>
		<dc:creator>Durand</dc:creator>
		<pubDate>Fri, 14 Dec 2007 21:18:02 +0000</pubDate>
		<guid isPermaLink="false">http://crazedmonkey.com/blog/programming/multiple-expression-if-statement-in-bash.html#comment-27960</guid>
		<description>Thanks, that was very useful</description>
		<content:encoded><![CDATA[<p>Thanks, that was very useful</p>
]]></content:encoded>
	</item>
</channel>
</rss>
