<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: if with multiple conditions in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/if-with-multiple-conditions/m-p/3980816#M95701</link>
    <description>Need to rectify my last post upon closer inspection. The parenthetical part will always be true so the IF can be written compactly as follows:&lt;BR /&gt;&lt;BR /&gt;if [ $syear -le $year ]; then&lt;BR /&gt;</description>
    <pubDate>Fri, 13 Apr 2007 15:34:16 GMT</pubDate>
    <dc:creator>Sandman!</dc:creator>
    <dc:date>2007-04-13T15:34:16Z</dc:date>
    <item>
      <title>if with multiple conditions</title>
      <link>https://community.hpe.com/t5/operating-system-linux/if-with-multiple-conditions/m-p/3980810#M95695</link>
      <description>Could some one please correct the below if with multiple conditions&lt;BR /&gt;if [[ $smonth -le $temp ]  &amp;amp;&amp;amp; [ $syear -le $year ]] ||  [[ $smonth -gt $temp ]&lt;BR /&gt;&amp;amp;&amp;amp; [ $syear -le $year ]]; then&lt;BR /&gt;&lt;BR /&gt;Thanking you in advance,</description>
      <pubDate>Fri, 13 Apr 2007 07:07:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/if-with-multiple-conditions/m-p/3980810#M95695</guid>
      <dc:creator>Kanan</dc:creator>
      <dc:date>2007-04-13T07:07:47Z</dc:date>
    </item>
    <item>
      <title>Re: if with multiple conditions</title>
      <link>https://community.hpe.com/t5/operating-system-linux/if-with-multiple-conditions/m-p/3980811#M95696</link>
      <description>Hi,&lt;BR /&gt;this depends on the logic you want to achieve !&lt;BR /&gt;But I would add another set of brackets around the whole statement, as at the moment you have :&lt;BR /&gt;if a || b ;then&lt;BR /&gt;&lt;BR /&gt;Please also read:&lt;BR /&gt;&lt;A href="http://forums1.itrc.hp.com/service/forums/helptips.do?#33" target="_blank"&gt;http://forums1.itrc.hp.com/service/forums/helptips.do?#33&lt;/A&gt; on how to reward any useful answers given to your questions.&lt;BR /&gt;&lt;BR /&gt;So far you have only awarded points to 3 of 11 answers  !&lt;BR /&gt;</description>
      <pubDate>Fri, 13 Apr 2007 07:31:23 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/if-with-multiple-conditions/m-p/3980811#M95696</guid>
      <dc:creator>Peter Godron</dc:creator>
      <dc:date>2007-04-13T07:31:23Z</dc:date>
    </item>
    <item>
      <title>Re: if with multiple conditions</title>
      <link>https://community.hpe.com/t5/operating-system-linux/if-with-multiple-conditions/m-p/3980812#M95697</link>
      <description>&lt;BR /&gt;You'll have to explain in words what you would like to accomplish.&lt;BR /&gt;&lt;BR /&gt;As written the statement looks wrong both in actual writing and in intent.&lt;BR /&gt;&lt;BR /&gt;Effectively the statement now says &lt;BR /&gt;if $syear le $year&lt;BR /&gt;&lt;BR /&gt;It 'looks' like you can to compare for a date range. Now consider $temp=3 $year=2007.&lt;BR /&gt;And $smonth=12, $syear=2006.&lt;BR /&gt;Do you want that combination to pass or fail.&lt;BR /&gt;&lt;BR /&gt;Yo may need to glue year and (zero-leading)month together before comparing (as string) or convert both to time-in-seconds.&lt;BR /&gt;&lt;BR /&gt;Hope this helps some,&lt;BR /&gt;Hein van den Heuvel (at gmail dot com)&lt;BR /&gt;HvdH Performance Consulting&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 13 Apr 2007 07:31:36 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/if-with-multiple-conditions/m-p/3980812#M95697</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2007-04-13T07:31:36Z</dc:date>
    </item>
    <item>
      <title>Re: if with multiple conditions</title>
      <link>https://community.hpe.com/t5/operating-system-linux/if-with-multiple-conditions/m-p/3980813#M95698</link>
      <description>Hey&lt;BR /&gt;&lt;BR /&gt;ksh:&lt;BR /&gt;if [ $smonth -le $temp -a  $syear -le $year  -o $smonth -gt $temp -o $syear -le $year ]&lt;BR /&gt; then&lt;BR /&gt;&lt;BR /&gt;...&lt;BR /&gt;&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;Regards</description>
      <pubDate>Fri, 13 Apr 2007 07:33:05 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/if-with-multiple-conditions/m-p/3980813#M95698</guid>
      <dc:creator>Oviwan</dc:creator>
      <dc:date>2007-04-13T07:33:05Z</dc:date>
    </item>
    <item>
      <title>Re: if with multiple conditions</title>
      <link>https://community.hpe.com/t5/operating-system-linux/if-with-multiple-conditions/m-p/3980814#M95699</link>
      <description>&lt;P&gt;If you need something understandable, you can write it in C, assuming the above variables are integers:&lt;BR /&gt;if (( smonth &amp;lt;= temp &amp;amp;&amp;amp; syear &amp;lt;= year || smonth &amp;gt; temp &amp;amp;&amp;amp; syear &amp;lt;= year )); then&lt;BR /&gt;&lt;BR /&gt;And as Hein say, this can be simplified to:&lt;BR /&gt;if [ (( syear &amp;lt;= year )) ]; then&lt;BR /&gt;&lt;BR /&gt;&amp;gt;Oviwan: ... -a ... -o ... -o&lt;BR /&gt;&lt;BR /&gt;Did you mean to have two -o?&lt;/P&gt;</description>
      <pubDate>Fri, 07 Oct 2011 08:17:46 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/if-with-multiple-conditions/m-p/3980814#M95699</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2011-10-07T08:17:46Z</dc:date>
    </item>
    <item>
      <title>Re: if with multiple conditions</title>
      <link>https://community.hpe.com/t5/operating-system-linux/if-with-multiple-conditions/m-p/3980815#M95700</link>
      <description>How about the following expr:&lt;BR /&gt;&lt;BR /&gt;if [ \( $smonth -le $temp -o $smonth -gt $temp \) -a $syear -le $year ]; then</description>
      <pubDate>Fri, 13 Apr 2007 15:10:03 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/if-with-multiple-conditions/m-p/3980815#M95700</guid>
      <dc:creator>Sandman!</dc:creator>
      <dc:date>2007-04-13T15:10:03Z</dc:date>
    </item>
    <item>
      <title>Re: if with multiple conditions</title>
      <link>https://community.hpe.com/t5/operating-system-linux/if-with-multiple-conditions/m-p/3980816#M95701</link>
      <description>Need to rectify my last post upon closer inspection. The parenthetical part will always be true so the IF can be written compactly as follows:&lt;BR /&gt;&lt;BR /&gt;if [ $syear -le $year ]; then&lt;BR /&gt;</description>
      <pubDate>Fri, 13 Apr 2007 15:34:16 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/if-with-multiple-conditions/m-p/3980816#M95701</guid>
      <dc:creator>Sandman!</dc:creator>
      <dc:date>2007-04-13T15:34:16Z</dc:date>
    </item>
    <item>
      <title>Re: if with multiple conditions</title>
      <link>https://community.hpe.com/t5/operating-system-linux/if-with-multiple-conditions/m-p/3980817#M95702</link>
      <description>&amp;gt;Sandman!: The parenthetical part will always be true&lt;BR /&gt;&lt;BR /&gt;That's what Hein said and I agreed.</description>
      <pubDate>Fri, 13 Apr 2007 17:27:43 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/if-with-multiple-conditions/m-p/3980817#M95702</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2007-04-13T17:27:43Z</dc:date>
    </item>
    <item>
      <title>Re: if with multiple conditions</title>
      <link>https://community.hpe.com/t5/operating-system-linux/if-with-multiple-conditions/m-p/3980818#M95703</link>
      <description>Thanks all for the immediate responses. My requirement is to have multiple condition in a single if statemnet. I have tried various combinations, but not got the correct one. Please correct me to the right sysntax. &lt;BR /&gt;&lt;BR /&gt;if [ &lt;CONDITION 1=""&gt; &amp;amp;&amp;amp; &lt;CONDITION 2=""&gt; ] OR [ &lt;CONDITION 3=""&gt; &amp;amp;&amp;amp; &lt;CONDITION 4=""&gt; ]&lt;BR /&gt;&lt;BR /&gt;thanks..&lt;/CONDITION&gt;&lt;/CONDITION&gt;&lt;/CONDITION&gt;&lt;/CONDITION&gt;</description>
      <pubDate>Sat, 14 Apr 2007 07:54:53 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/if-with-multiple-conditions/m-p/3980818#M95703</guid>
      <dc:creator>Kanan</dc:creator>
      <dc:date>2007-04-14T07:54:53Z</dc:date>
    </item>
    <item>
      <title>Re: if with multiple conditions</title>
      <link>https://community.hpe.com/t5/operating-system-linux/if-with-multiple-conditions/m-p/3980819#M95704</link>
      <description>&lt;P&gt;&amp;gt;Please correct me to the right syntax.&lt;BR /&gt;&lt;BR /&gt;I did, if these are numbers and not strings:&lt;BR /&gt;if (( smonth &amp;lt;= temp &amp;amp;&amp;amp; syear &amp;lt;= year || smonth &amp;gt; temp &amp;amp;&amp;amp; syear &amp;lt;= year )); then&lt;BR /&gt;&lt;BR /&gt;Otherwise you have to use:&lt;BR /&gt;if [[ X &amp;amp;&amp;amp; Y || Z &amp;amp;&amp;amp; W ]]; then&lt;/P&gt;</description>
      <pubDate>Fri, 07 Oct 2011 08:18:38 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/if-with-multiple-conditions/m-p/3980819#M95704</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2011-10-07T08:18:38Z</dc:date>
    </item>
    <item>
      <title>Re: if with multiple conditions</title>
      <link>https://community.hpe.com/t5/operating-system-linux/if-with-multiple-conditions/m-p/3980820#M95705</link>
      <description>Hi Kanan:&lt;BR /&gt;&lt;BR /&gt;# if [ \( condition1 -a condition2 \) -o \( condition3 -a condition4 \) ]; then&lt;BR /&gt;...&lt;BR /&gt;&lt;BR /&gt;The '-a' means "and"; the '-o' means "or".  The parentheses are escaped because they are special to the shell.  See the manpages for 'test(1)'.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Sat, 14 Apr 2007 10:54:21 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/if-with-multiple-conditions/m-p/3980820#M95705</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2007-04-14T10:54:21Z</dc:date>
    </item>
    <item>
      <title>Re: if with multiple conditions</title>
      <link>https://community.hpe.com/t5/operating-system-linux/if-with-multiple-conditions/m-p/3980821#M95706</link>
      <description>Dennis, I have tried your suggestion but it gives syntax error. I believe u guys not understood my question. Below is more details.&lt;BR /&gt;&lt;BR /&gt;I have 4 conditions. I want either 1&amp;amp;2 or 3&amp;amp;4 condition should match. All are string values. &lt;BR /&gt;[ condition 1 AND condition 2 ]  OR  [ Condition 3 AND condition 4 ]&lt;BR /&gt;&lt;BR /&gt;Please help me.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Sun, 15 Apr 2007 08:21:13 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/if-with-multiple-conditions/m-p/3980821#M95706</guid>
      <dc:creator>Kanan</dc:creator>
      <dc:date>2007-04-15T08:21:13Z</dc:date>
    </item>
    <item>
      <title>Re: if with multiple conditions</title>
      <link>https://community.hpe.com/t5/operating-system-linux/if-with-multiple-conditions/m-p/3980822#M95707</link>
      <description>&lt;!--!*#--&gt;Try the exemplary string expression evaluations below:&lt;BR /&gt;&lt;BR /&gt;if [[ "$str1" = "$str2" &amp;amp;&amp;amp; "$str3" ]] || [[ -z "$str4" &amp;amp;&amp;amp; -n "$str5" ]]; then&lt;BR /&gt;   statements&lt;BR /&gt;fi</description>
      <pubDate>Sun, 15 Apr 2007 13:34:49 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/if-with-multiple-conditions/m-p/3980822#M95707</guid>
      <dc:creator>Sandman!</dc:creator>
      <dc:date>2007-04-15T13:34:49Z</dc:date>
    </item>
    <item>
      <title>Re: if with multiple conditions</title>
      <link>https://community.hpe.com/t5/operating-system-linux/if-with-multiple-conditions/m-p/3980823#M95708</link>
      <description>Hi (again) Kanan:&lt;BR /&gt;&lt;BR /&gt;&amp;gt; [ condition 1 AND condition 2 ] OR [ Condition 3 AND condition 4 ]&lt;BR /&gt;&lt;BR /&gt;As I wrote before, this is a valid shell syntax for this:&lt;BR /&gt;&lt;BR /&gt;# if [ \( condition1 -a condition2 \) -o \( condition3 -a condition4 \) ]; then&lt;BR /&gt;...&lt;BR /&gt;&lt;BR /&gt;For example:&lt;BR /&gt;&lt;BR /&gt;# if [ \( "${A}" = "${B}" -a "${C}" = "${D}" \) -o \( "${X}" != "${Y}" -a "${X}" != "${Z}" \) ]; then&lt;BR /&gt;...&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Sun, 15 Apr 2007 14:15:05 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/if-with-multiple-conditions/m-p/3980823#M95708</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2007-04-15T14:15:05Z</dc:date>
    </item>
    <item>
      <title>Re: if with multiple conditions</title>
      <link>https://community.hpe.com/t5/operating-system-linux/if-with-multiple-conditions/m-p/3980824#M95709</link>
      <description>Hi James,&lt;BR /&gt;&lt;BR /&gt;its giving syntax error again. FYI, my shell is ksh.</description>
      <pubDate>Sun, 15 Apr 2007 23:11:33 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/if-with-multiple-conditions/m-p/3980824#M95709</guid>
      <dc:creator>Kanan</dc:creator>
      <dc:date>2007-04-15T23:11:33Z</dc:date>
    </item>
    <item>
      <title>Re: if with multiple conditions</title>
      <link>https://community.hpe.com/t5/operating-system-linux/if-with-multiple-conditions/m-p/3980825#M95710</link>
      <description>&lt;P&gt;All of these syntaxes are valid:&lt;BR /&gt;if (( smonth &amp;lt;= temp &amp;amp;&amp;amp; syear &amp;lt;= year || smonth &amp;gt; temp &amp;amp;&amp;amp; syear &amp;lt;= year )); then&lt;BR /&gt;&lt;BR /&gt;if [[ X &amp;amp;&amp;amp; Y || Z &amp;amp;&amp;amp; W ]]; then&lt;BR /&gt;&lt;BR /&gt;if [ \( condition1 -a condition2 \) -o \( condition3 -a condition4 \) ]; then&lt;BR /&gt;&lt;BR /&gt;(In the above case, the use of () is redundant but may make it clearer.)&lt;BR /&gt;&lt;BR /&gt;&amp;gt;I believe you guys not understood my question. I want either 1&amp;amp;2 or 3&amp;amp;4 condition should match. All are string values.&lt;BR /&gt;&lt;BR /&gt;Sure we have. But this is the first time you said they were strings. This makes my (( )) solution invalid. Though in most cases if your variables have numeric values, they can be treated as numbers.&lt;BR /&gt;&lt;BR /&gt;&amp;gt;Sandman: if [[ "$str1" = "$str2" &amp;amp;&amp;amp; "$str3" ]] || [[ -z "$str4" &amp;amp;&amp;amp; -n "$str5" ]]; then&lt;BR /&gt;&lt;BR /&gt;This isn't valid. You only need one set of [[ ]]:&lt;BR /&gt;if [[ "$str1" = "$str2" &amp;amp;&amp;amp; "$str9" = "$str3" || -z "$str4" &amp;amp;&amp;amp; -n "$str5" ]]; then&lt;BR /&gt;&lt;BR /&gt;&amp;gt;JRF:&lt;BR /&gt;if [ \( "${A}" = "${B}" -a "${C}" = "${D}" \) -o \( "${X}" != "${Y}" -a "${X}" != "${Z}" \) ]; then&lt;BR /&gt;&lt;BR /&gt;&amp;gt;its giving syntax error again. FYI, my shell is ksh.&lt;BR /&gt;&lt;BR /&gt;That syntax is perfectly valid. You need that exact spacing.&lt;BR /&gt;&lt;BR /&gt;Using your original case:&lt;BR /&gt;if [[ ! ( $smonth &amp;gt; $temp ) &amp;amp;&amp;amp; ! ( $syear &amp;gt; $year ) || $smonth &amp;gt; $temp &amp;amp;&amp;amp; ! ( $syear &amp;gt; $year ) ]]; then&lt;BR /&gt;&lt;BR /&gt;If these variables can be empty, you would need to quote them. If the variables contain a leading "-", you would have to prefix a "X".&lt;/P&gt;</description>
      <pubDate>Fri, 07 Oct 2011 08:22:05 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/if-with-multiple-conditions/m-p/3980825#M95710</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2011-10-07T08:22:05Z</dc:date>
    </item>
    <item>
      <title>Re: if with multiple conditions</title>
      <link>https://community.hpe.com/t5/operating-system-linux/if-with-multiple-conditions/m-p/3980826#M95711</link>
      <description>I forgot to mention, if you are having problems with our solutions, you should attach what you tried.</description>
      <pubDate>Mon, 16 Apr 2007 02:51:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/if-with-multiple-conditions/m-p/3980826#M95711</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2007-04-16T02:51:45Z</dc:date>
    </item>
    <item>
      <title>Re: if with multiple conditions</title>
      <link>https://community.hpe.com/t5/operating-system-linux/if-with-multiple-conditions/m-p/3980827#M95712</link>
      <description>It appears you can't use \( or \) within [[ ]], so my example should be:&lt;BR /&gt;if [[ ! ( $smonth &amp;gt; $temp ) &amp;amp;&amp;amp; ! ( $syear &amp;gt; $year ) || $smonth &amp;gt; $temp &amp;amp;&amp;amp; ! ( $syear &amp;gt; $year ) ]]; then&lt;BR /&gt;&lt;BR /&gt;The "!" is needed because there are no &amp;lt;= or &amp;gt;= string compares.</description>
      <pubDate>Mon, 16 Apr 2007 21:03:49 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/if-with-multiple-conditions/m-p/3980827#M95712</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2007-04-16T21:03:49Z</dc:date>
    </item>
  </channel>
</rss>

