<?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.. then..else statement in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/if-then-else-statement/m-p/3513903#M844341</link>
    <description>This should do the trick:&lt;BR /&gt;if [ "var$1" -eq "one" ] &amp;amp;&amp;amp; [ "$var2" -eq "two" ]&lt;BR /&gt;then&lt;BR /&gt;....&lt;BR /&gt;else&lt;BR /&gt;....&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;I like to quote the variables in case they are not set. That way you at least have an emty string.&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Trond</description>
    <pubDate>Wed, 30 Mar 2005 01:02:24 GMT</pubDate>
    <dc:creator>Trond Haugen</dc:creator>
    <dc:date>2005-03-30T01:02:24Z</dc:date>
    <item>
      <title>if.. then..else statement</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/if-then-else-statement/m-p/3513899#M844337</link>
      <description>Dear Gurus,&lt;BR /&gt;Am creating a script for testing two variable. The 2 variable that needs to be satisified before executing the command. I would like to ask what should the syntax be? &lt;BR /&gt;&lt;BR /&gt;Is it...&lt;BR /&gt;&lt;BR /&gt;If [ var$1 -eq $var2 ] and [ $var3 = $var4 ]&lt;BR /&gt;then ....&lt;BR /&gt;else ....&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;Maximum points for all correct replies.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 29 Mar 2005 23:05:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/if-then-else-statement/m-p/3513899#M844337</guid>
      <dc:creator>Pando</dc:creator>
      <dc:date>2005-03-29T23:05:06Z</dc:date>
    </item>
    <item>
      <title>Re: if.. then..else statement</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/if-then-else-statement/m-p/3513900#M844338</link>
      <description>hi,&lt;BR /&gt;&lt;BR /&gt;if [ var$1 -eq $var2 ] &amp;amp;&amp;amp; [ $var3 = $var4 ]&lt;BR /&gt;then ....&lt;BR /&gt;else ....&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;regards.&lt;BR /&gt;</description>
      <pubDate>Tue, 29 Mar 2005 23:17:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/if-then-else-statement/m-p/3513900#M844338</guid>
      <dc:creator>Joseph Loo</dc:creator>
      <dc:date>2005-03-29T23:17:31Z</dc:date>
    </item>
    <item>
      <title>Re: if.. then..else statement</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/if-then-else-statement/m-p/3513901#M844339</link>
      <description>If $var1/2/3/4 are integer numbers, you should use&lt;BR /&gt;following:&lt;BR /&gt;&lt;BR /&gt;if [ $var1 -eq $var2 ]  &amp;amp;&amp;amp; [ $var3 -eq $var4 ]&lt;BR /&gt;then&lt;BR /&gt;..&lt;BR /&gt;else&lt;BR /&gt;..&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;You could use = instead of -eq in the if statement&lt;BR /&gt;and it would work just as good even if var1/2/3/4 are&lt;BR /&gt;integers or strings.&lt;BR /&gt;&lt;BR /&gt;- Biswajit&lt;BR /&gt;</description>
      <pubDate>Tue, 29 Mar 2005 23:37:46 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/if-then-else-statement/m-p/3513901#M844339</guid>
      <dc:creator>Biswajit Tripathy</dc:creator>
      <dc:date>2005-03-29T23:37:46Z</dc:date>
    </item>
    <item>
      <title>Re: if.. then..else statement</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/if-then-else-statement/m-p/3513902#M844340</link>
      <description>You can do this as,&lt;BR /&gt;&lt;BR /&gt;if [[ $var1 -eq $var2 &amp;amp;&amp;amp; $var3 -eq $var4 ]]&lt;BR /&gt;then&lt;BR /&gt;  echo "Correct"&lt;BR /&gt;else&lt;BR /&gt;  echo "wrong"&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;Example:&lt;BR /&gt;&lt;BR /&gt;#!/bin/bash&lt;BR /&gt;var1=1&lt;BR /&gt;var2=1&lt;BR /&gt;var3=3&lt;BR /&gt;var4=3&lt;BR /&gt;&lt;BR /&gt;if [[ $var1 -eq $var2 &amp;amp;&amp;amp; $var3 -eq $var4 ]]&lt;BR /&gt;then&lt;BR /&gt;  echo "Correct"&lt;BR /&gt;else&lt;BR /&gt;  echo "wrong"&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;Output:&lt;BR /&gt;Correct</description>
      <pubDate>Wed, 30 Mar 2005 00:47:29 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/if-then-else-statement/m-p/3513902#M844340</guid>
      <dc:creator>Muthukumar_5</dc:creator>
      <dc:date>2005-03-30T00:47:29Z</dc:date>
    </item>
    <item>
      <title>Re: if.. then..else statement</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/if-then-else-statement/m-p/3513903#M844341</link>
      <description>This should do the trick:&lt;BR /&gt;if [ "var$1" -eq "one" ] &amp;amp;&amp;amp; [ "$var2" -eq "two" ]&lt;BR /&gt;then&lt;BR /&gt;....&lt;BR /&gt;else&lt;BR /&gt;....&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;I like to quote the variables in case they are not set. That way you at least have an emty string.&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Trond</description>
      <pubDate>Wed, 30 Mar 2005 01:02:24 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/if-then-else-statement/m-p/3513903#M844341</guid>
      <dc:creator>Trond Haugen</dc:creator>
      <dc:date>2005-03-30T01:02:24Z</dc:date>
    </item>
    <item>
      <title>Re: if.. then..else statement</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/if-then-else-statement/m-p/3513904#M844342</link>
      <description>An important detail about replies above:&lt;BR /&gt;&lt;BR /&gt;Beware of '-eq' and '=' operators. They are   slightly different: '-eq' is a integer comparison but '=' is a string comparison.&lt;BR /&gt;Examples:&lt;BR /&gt;&lt;BR /&gt;[[ 0 -eq 0000 ]]; echo $? # shows 0 (true)&lt;BR /&gt;[[ 0  =  0000 ]]; echo $? # shows 1 (false)&lt;BR /&gt;&lt;BR /&gt;Of course, don't forget to surround each $var1 with double quotes to prevent null chars.</description>
      <pubDate>Wed, 30 Mar 2005 05:50:23 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/if-then-else-statement/m-p/3513904#M844342</guid>
      <dc:creator>Jdamian</dc:creator>
      <dc:date>2005-03-30T05:50:23Z</dc:date>
    </item>
    <item>
      <title>Re: if.. then..else statement</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/if-then-else-statement/m-p/3513905#M844343</link>
      <description>Hmm do not use and operator, shell use (&amp;amp;&amp;amp;) as and operation.&lt;BR /&gt;like this:&lt;BR /&gt;if [ var$1 -eq $var2 ] &amp;amp;&amp;amp; [ $var3 = $var4 ]&lt;BR /&gt;then &lt;BR /&gt;your_commands&lt;BR /&gt;else &lt;BR /&gt;your_commands&lt;BR /&gt;fi&lt;BR /&gt;That all&lt;BR /&gt;You can refer docs at&lt;BR /&gt;&lt;A href="http://docs.hp.com/en/B2355-90046/index.html" target="_blank"&gt;http://docs.hp.com/en/B2355-90046/index.html&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;HTH&lt;BR /&gt;tienna&lt;BR /&gt;</description>
      <pubDate>Wed, 30 Mar 2005 05:59:25 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/if-then-else-statement/m-p/3513905#M844343</guid>
      <dc:creator>Nguyen Anh Tien</dc:creator>
      <dc:date>2005-03-30T05:59:25Z</dc:date>
    </item>
    <item>
      <title>Re: if.. then..else statement</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/if-then-else-statement/m-p/3513906#M844344</link>
      <description>if [ $var1 -eq $var2 -a $var3 = $var4 ]&lt;BR /&gt; &lt;BR /&gt;-eq for numeric compare&lt;BR /&gt;= for string compare&lt;BR /&gt;-a is "and" operator&lt;BR /&gt; &lt;BR /&gt;Do a "man test" for more info&lt;BR /&gt; &lt;BR /&gt;HTH&lt;BR /&gt; &lt;BR /&gt;-- Rod Hills</description>
      <pubDate>Wed, 30 Mar 2005 10:41:24 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/if-then-else-statement/m-p/3513906#M844344</guid>
      <dc:creator>Rodney Hills</dc:creator>
      <dc:date>2005-03-30T10:41:24Z</dc:date>
    </item>
    <item>
      <title>Re: if.. then..else statement</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/if-then-else-statement/m-p/3513907#M844345</link>
      <description>Use the double &amp;amp;&amp;amp; for the logical AND.&lt;BR /&gt;&lt;BR /&gt;The -a will work as well.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 30 Mar 2005 10:43:12 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/if-then-else-statement/m-p/3513907#M844345</guid>
      <dc:creator>Rick Garland</dc:creator>
      <dc:date>2005-03-30T10:43:12Z</dc:date>
    </item>
    <item>
      <title>Re: if.. then..else statement</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/if-then-else-statement/m-p/3513908#M844346</link>
      <description>Fernando&lt;BR /&gt;do not forget to assign point to answer</description>
      <pubDate>Thu, 31 Mar 2005 05:48:28 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/if-then-else-statement/m-p/3513908#M844346</guid>
      <dc:creator>Nguyen Anh Tien</dc:creator>
      <dc:date>2005-03-31T05:48:28Z</dc:date>
    </item>
    <item>
      <title>Re: if.. then..else statement</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/if-then-else-statement/m-p/3513909#M844347</link>
      <description>OK here it is to an extreme&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;#doit XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&lt;BR /&gt;&lt;BR /&gt;var1=$1&lt;BR /&gt;var2=$2&lt;BR /&gt;var3=$3&lt;BR /&gt;var4=$4&lt;BR /&gt;&lt;BR /&gt;if&lt;BR /&gt;   [ "${var1}" = "${var2}" -a "${var3}" = "${var4}" ]&lt;BR /&gt;&lt;BR /&gt;then&lt;BR /&gt;   echo "${var1} equals ${var2} and ${var3} equals ${var4}"&lt;BR /&gt;&lt;BR /&gt;elif&lt;BR /&gt;   [ "${var1}" != "${var2}" -a "${var3}" = "${var4}" ]&lt;BR /&gt;   then&lt;BR /&gt;      echo "${var1} does not equal ${var2} and ${var3} equal ${var4}"&lt;BR /&gt;   elif&lt;BR /&gt;       [ "${var1}" = "${var2}" -a "${var3}" != "${var4}" ]&lt;BR /&gt;   then&lt;BR /&gt;      echo "${var1}  equal ${var2} and ${var3} does not equal ${var4}"&lt;BR /&gt;else&lt;BR /&gt;   echo "${var1}  does not equal ${var2} and ${var3} does not equal ${var4}"&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;##########################&lt;BR /&gt;#doit one one two two&lt;BR /&gt;one equals one and two equals two&lt;BR /&gt;&lt;BR /&gt;#doit 1 2 3 4&lt;BR /&gt;1  does not equal 2 and 3 does not equal 4&lt;BR /&gt;&lt;BR /&gt;#doit 1 1  3 4&lt;BR /&gt;1  equal 1 and 3 does not equal 4&lt;BR /&gt;&lt;BR /&gt;Hope it is readable.&lt;BR /&gt;Rory</description>
      <pubDate>Thu, 31 Mar 2005 11:35:22 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/if-then-else-statement/m-p/3513909#M844347</guid>
      <dc:creator>Rory R Hammond</dc:creator>
      <dc:date>2005-03-31T11:35:22Z</dc:date>
    </item>
  </channel>
</rss>

