<?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: nested if else statement in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/nested-if-else-statement/m-p/4307419#M338844</link>
    <description>Hi,&lt;BR /&gt;&lt;BR /&gt;why don't you also post your errors you've got?&lt;BR /&gt;In sh-shell or ksh-shell OR is ||, AND is &amp;amp;&amp;amp;:&lt;BR /&gt;&lt;BR /&gt;if [[ $Num = 0  ||  $Num = 1 ]]; then&lt;BR /&gt;if [[ $Num = 10 &amp;amp;&amp;amp;  $Char = 'Y' ]]; then&lt;BR /&gt;&lt;BR /&gt;Are we doing your homework?&lt;BR /&gt;&lt;BR /&gt;Volkmar&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Mon, 17 Nov 2008 14:13:18 GMT</pubDate>
    <dc:creator>V. Nyga</dc:creator>
    <dc:date>2008-11-17T14:13:18Z</dc:date>
    <item>
      <title>nested if else statement</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/nested-if-else-statement/m-p/4307413#M338838</link>
      <description>Hi all,&lt;BR /&gt;&lt;BR /&gt;I want to execute if else in such a way:&lt;BR /&gt;&lt;BR /&gt;Num=10&lt;BR /&gt;Char='Y'&lt;BR /&gt;&lt;BR /&gt;if [ $Num = [0 OR 1 OR 2] ]; then&lt;BR /&gt;    echo " Num is &amp;gt; 0 but &amp;lt; 3 "&lt;BR /&gt;else &lt;BR /&gt;      if [ $Num = 3 OR 4] and $Char='Y' ];then&lt;BR /&gt;         echo " num &amp;lt; 5 and char is : 'Y'&lt;BR /&gt;      else&lt;BR /&gt;       echo " num &amp;gt; 5 and char is : 'N'&lt;BR /&gt;       fi;&lt;BR /&gt;fi;&lt;BR /&gt;&lt;BR /&gt;Can some one please help me to right correctly these conditions.&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;BR /&gt;&lt;BR /&gt;        &lt;BR /&gt;</description>
      <pubDate>Mon, 17 Nov 2008 11:54:28 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/nested-if-else-statement/m-p/4307413#M338838</guid>
      <dc:creator>diwakar_4</dc:creator>
      <dc:date>2008-11-17T11:54:28Z</dc:date>
    </item>
    <item>
      <title>Re: nested if else statement</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/nested-if-else-statement/m-p/4307414#M338839</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;The following will do,&lt;BR /&gt;&lt;BR /&gt;Num=3&lt;BR /&gt;Char='Y'&lt;BR /&gt;&lt;BR /&gt;if [ $Num -ge 0 -a $Num -lt 3 ] ; then&lt;BR /&gt;   echo " Num is &amp;gt; 0 but &amp;lt; 3 "&lt;BR /&gt;elif [ $Num -eq 3 -o $Num -eq 4 ] ; then&lt;BR /&gt;     if [[ $Char = 'Y' ]] ; then&lt;BR /&gt;      echo " num &amp;lt; 5 and char is : 'Y'"&lt;BR /&gt;     fi&lt;BR /&gt;elif [[ $Char = 'N' ]]  ; then&lt;BR /&gt;     echo " num &amp;gt; 5 and char is : 'N'"&lt;BR /&gt;else&lt;BR /&gt;     echo " num &amp;gt; 5 and char is : 'Y' "&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Ninad</description>
      <pubDate>Mon, 17 Nov 2008 12:21:51 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/nested-if-else-statement/m-p/4307414#M338839</guid>
      <dc:creator>Ninad_1</dc:creator>
      <dc:date>2008-11-17T12:21:51Z</dc:date>
    </item>
    <item>
      <title>Re: nested if else statement</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/nested-if-else-statement/m-p/4307415#M338840</link>
      <description>&lt;!--!*#--&gt;I think this would be easier solved by using Case statement instead of if's. But I'm guessing you have a plan for this so here we go :).&lt;BR /&gt;&lt;BR /&gt;if [ $Num -ge 0 -a $Num -lt 3 ]; then&lt;BR /&gt;   echo "Num is &amp;gt; 0 but &amp;lt; 3"&lt;BR /&gt;else&lt;BR /&gt;   if [ $Num -ge 3 -a $Num -le 4 ]; then&lt;BR /&gt;      if [ "$Char" == "Y" ]; then&lt;BR /&gt;         echo " num &amp;lt; 5 and char is : 'Y'"&lt;BR /&gt;      else&lt;BR /&gt;         echo " num &amp;lt; 5 and char is : 'N'"&lt;BR /&gt;      fi&lt;BR /&gt;   elif [ $Num -ge 5 ]; then&lt;BR /&gt;      if [ "$Char" == "Y" ]; then&lt;BR /&gt;         echo " num &amp;gt; 5 and char is : 'Y'"&lt;BR /&gt;      else&lt;BR /&gt;         echo " num &amp;gt; 5 and char is : 'N'"&lt;BR /&gt;      fi&lt;BR /&gt;   fi&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;I made som modifications to yours since it didn't account for all the possible versions. And I added a elif :)&lt;BR /&gt;&lt;BR /&gt;Best regards&lt;BR /&gt;Fredrik Eriksson</description>
      <pubDate>Mon, 17 Nov 2008 12:22:28 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/nested-if-else-statement/m-p/4307415#M338840</guid>
      <dc:creator>Fredrik.eriksson</dc:creator>
      <dc:date>2008-11-17T12:22:28Z</dc:date>
    </item>
    <item>
      <title>Re: nested if else statement</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/nested-if-else-statement/m-p/4307416#M338841</link>
      <description>Hi Ninad/Fredrik,&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;if [ $Num = 3 OR 4] and $Char='Y' ];then&lt;BR /&gt;&lt;BR /&gt;I want above condition in one line rathar than spiliting in many lines.&lt;BR /&gt;&lt;BR /&gt;Can you suggets..&lt;BR /&gt;</description>
      <pubDate>Mon, 17 Nov 2008 12:45:35 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/nested-if-else-statement/m-p/4307416#M338841</guid>
      <dc:creator>diwakar_4</dc:creator>
      <dc:date>2008-11-17T12:45:35Z</dc:date>
    </item>
    <item>
      <title>Re: nested if else statement</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/nested-if-else-statement/m-p/4307417#M338842</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I do not see any benefit in putting everything in one line, except for code being a bit long.&lt;BR /&gt;Infact u should have the 2 conditions separate so as to also check for Char = N even if Num=3 or 4.&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Ninad</description>
      <pubDate>Mon, 17 Nov 2008 12:52:24 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/nested-if-else-statement/m-p/4307417#M338842</guid>
      <dc:creator>Ninad_1</dc:creator>
      <dc:date>2008-11-17T12:52:24Z</dc:date>
    </item>
    <item>
      <title>Re: nested if else statement</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/nested-if-else-statement/m-p/4307418#M338843</link>
      <description>&amp;gt;I want condition in one line rather than splitting in many lines.&lt;BR /&gt;if [ $Num = 3 OR 4] and $Char='Y' ];then&lt;BR /&gt;&lt;BR /&gt;if [ \( $Num -eq 3 -o $Num -eq 4 \) -a "$Char" = "Y" ]; then</description>
      <pubDate>Mon, 17 Nov 2008 13:53:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/nested-if-else-statement/m-p/4307418#M338843</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2008-11-17T13:53:52Z</dc:date>
    </item>
    <item>
      <title>Re: nested if else statement</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/nested-if-else-statement/m-p/4307419#M338844</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;why don't you also post your errors you've got?&lt;BR /&gt;In sh-shell or ksh-shell OR is ||, AND is &amp;amp;&amp;amp;:&lt;BR /&gt;&lt;BR /&gt;if [[ $Num = 0  ||  $Num = 1 ]]; then&lt;BR /&gt;if [[ $Num = 10 &amp;amp;&amp;amp;  $Char = 'Y' ]]; then&lt;BR /&gt;&lt;BR /&gt;Are we doing your homework?&lt;BR /&gt;&lt;BR /&gt;Volkmar&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 17 Nov 2008 14:13:18 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/nested-if-else-statement/m-p/4307419#M338844</guid>
      <dc:creator>V. Nyga</dc:creator>
      <dc:date>2008-11-17T14:13:18Z</dc:date>
    </item>
    <item>
      <title>Re: nested if else statement</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/nested-if-else-statement/m-p/4307420#M338845</link>
      <description>Hi Diwakar,&lt;BR /&gt;&lt;BR /&gt;The shell script will be,&lt;BR /&gt;&lt;BR /&gt;Num=10&lt;BR /&gt;Char='Y'&lt;BR /&gt;&lt;BR /&gt;if [ $Num -eq 0 -o $Num -eq 1 -o $Num -eq 2 ]; then&lt;BR /&gt;    echo " Num is &amp;gt; 0 but &amp;lt; 3 "&lt;BR /&gt;else &lt;BR /&gt;    if [ $Num -eq 3 -o $Num -eq 4 ]&amp;amp;[ "$Char" = "Y" ];then&lt;BR /&gt;        echo " num &amp;lt; 5 and char is : 'Y'"&lt;BR /&gt;    else&lt;BR /&gt;        echo " num &amp;gt; 5 and char is : 'N'"&lt;BR /&gt;    fi&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;--------------------------------------------&lt;BR /&gt;# OR&lt;BR /&gt;Num=10&lt;BR /&gt;Char='Y'&lt;BR /&gt;&lt;BR /&gt;if [ $Num -eq 0 -o $Num -eq 1 -o $Num -eq 2 ]; then&lt;BR /&gt;    echo " Num is &amp;gt; 0 but &amp;lt; 3 "&lt;BR /&gt;elif [ $Num -eq 3 -o $Num -eq 4 ]&amp;amp;[ "$Char" = "Y" ];then&lt;BR /&gt;    echo " num &amp;lt; 5 and char is : 'Y'"&lt;BR /&gt;else&lt;BR /&gt;    echo " num &amp;gt; 5 and char is : 'N'"&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;OK Rules of the test for shell script:&lt;BR /&gt;Comparison operator&lt;BR /&gt;-------------------&lt;BR /&gt;- Numeric: -eq -ne -lt -le -gt -ge&lt;BR /&gt;- String: = !=&lt;BR /&gt;&lt;BR /&gt;Logical operator&lt;BR /&gt;----------------&lt;BR /&gt;Numeric: ! Not&lt;BR /&gt;        -a And&lt;BR /&gt;        -o Or&lt;BR /&gt;String:  ! Not&lt;BR /&gt;        &amp;amp;&amp;amp; And&lt;BR /&gt;        || Or&lt;BR /&gt;&lt;BR /&gt;OK,&lt;BR /&gt;- If you want to make two numeric comparision with and&lt;BR /&gt;if [ Cond1 -a Cond2 ];then # Here Cond like $a -lt 5 &lt;BR /&gt;&lt;BR /&gt;- If you want to make and with or&lt;BR /&gt;if [ Cond1 -a Cond2 -o Cond3 ];then&lt;BR /&gt;&lt;BR /&gt;- But you want to change the order of testing&lt;BR /&gt;if [ Cond1 -s \( Cond2 -a Cond3 \) ];then&lt;BR /&gt;#Here spaces are important&lt;BR /&gt;&lt;BR /&gt;- You want to compare two strings with and or or&lt;BR /&gt;&lt;BR /&gt;if [ Cond1 ]&amp;amp;&amp;amp;[ Cond2 ]||[Cond3 ];then&lt;BR /&gt;&lt;BR /&gt;Similarly you want to compare integer comparision with string with and&lt;BR /&gt;&lt;BR /&gt;if [ intCond ]&amp;amp;&amp;amp;[ stringCond ];then&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;I hope now you will be able to do all possible comarisions. &lt;BR /&gt;&lt;BR /&gt;Rgds&lt;BR /&gt;-NKG-</description>
      <pubDate>Tue, 18 Nov 2008 04:38:55 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/nested-if-else-statement/m-p/4307420#M338845</guid>
      <dc:creator>Nitin Kumar Gupta</dc:creator>
      <dc:date>2008-11-18T04:38:55Z</dc:date>
    </item>
    <item>
      <title>Re: nested if else statement</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/nested-if-else-statement/m-p/4307421#M338846</link>
      <description>Also,&lt;BR /&gt;&lt;BR /&gt;for if, else, nested if else&lt;BR /&gt;1)&lt;BR /&gt;if ...&lt;BR /&gt;then&lt;BR /&gt;    ....&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;2) &lt;BR /&gt;if ....&lt;BR /&gt;then&lt;BR /&gt;    ....&lt;BR /&gt;else&lt;BR /&gt;    ....&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;3)&lt;BR /&gt;if ....&lt;BR /&gt;then&lt;BR /&gt;    ....&lt;BR /&gt;else&lt;BR /&gt;    if ....&lt;BR /&gt;    then&lt;BR /&gt;        ....&lt;BR /&gt;    fi&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;can be &lt;BR /&gt;&lt;BR /&gt;if ....&lt;BR /&gt;then&lt;BR /&gt;    ....&lt;BR /&gt;elif ....&lt;BR /&gt;then&lt;BR /&gt;    ....&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;I think you will be able to make all possible condition type.&lt;BR /&gt;&lt;BR /&gt;Rgds&lt;BR /&gt;-NKG-&lt;BR /&gt;</description>
      <pubDate>Tue, 18 Nov 2008 04:42:02 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/nested-if-else-statement/m-p/4307421#M338846</guid>
      <dc:creator>Nitin Kumar Gupta</dc:creator>
      <dc:date>2008-11-18T04:42:02Z</dc:date>
    </item>
    <item>
      <title>Re: nested if else statement</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/nested-if-else-statement/m-p/4307422#M338847</link>
      <description>&amp;gt;Nitin: elif [ $Num -eq 3 -o $Num -eq 4 ]&amp;amp;[ "$Char" = "Y" ];then&lt;BR /&gt;&lt;BR /&gt;That should be "&amp;amp;&amp;amp;":&lt;BR /&gt;elif [ $Num -eq 3 -o $Num -eq 4 ] &amp;amp;&amp;amp; [ "$Char" = "Y" ]; then&lt;BR /&gt;Or using arithmetic expressions:&lt;BR /&gt;elif (( Num == 3 &amp;amp;&amp;amp; Num == 4 )) &amp;amp;&amp;amp; [ "$Char" = "Y" ]; then&lt;BR /&gt;&lt;BR /&gt;&amp;gt;You want to compare two strings with and or or&lt;BR /&gt;if [ Cond1 ]&amp;amp;&amp;amp;[ Cond2 ]||[Cond3 ]; then&lt;BR /&gt;&lt;BR /&gt;There is no need to use multiple test operators, you can use -a or -o&lt;BR /&gt;&lt;BR /&gt;&amp;gt;if [ Cond1 -s \( Cond2 -a Cond3 \) ];then&lt;BR /&gt;&lt;BR /&gt;I assume that -s should be -o.</description>
      <pubDate>Tue, 18 Nov 2008 05:12:39 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/nested-if-else-statement/m-p/4307422#M338847</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2008-11-18T05:12:39Z</dc:date>
    </item>
    <item>
      <title>Re: nested if else statement</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/nested-if-else-statement/m-p/4307423#M338848</link>
      <description>Hello Dennis,&lt;BR /&gt;&lt;BR /&gt;Thanks to correct my typographical errors. And also thanks to tell me more about string comparisions.&lt;BR /&gt;&lt;BR /&gt;-NKG-</description>
      <pubDate>Tue, 18 Nov 2008 06:06:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/nested-if-else-statement/m-p/4307423#M338848</guid>
      <dc:creator>Nitin Kumar Gupta</dc:creator>
      <dc:date>2008-11-18T06:06:45Z</dc:date>
    </item>
    <item>
      <title>Re: nested if else statement</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/nested-if-else-statement/m-p/4307424#M338849</link>
      <description>&lt;!--!*#--&gt;And Diwakar,&lt;BR /&gt;&lt;BR /&gt;Your solution would be,&lt;BR /&gt;&lt;BR /&gt;Num=10&lt;BR /&gt;Char='Y'&lt;BR /&gt;&lt;BR /&gt;if [ $Num -eq 0 -o $Num -eq 1 -o $Num -eq 2 ]; then&lt;BR /&gt;    echo "Num is &amp;gt; 0 but &amp;lt; 3"&lt;BR /&gt;elif [ $Num -eq 3 -o $Num -eq 4 ]&amp;amp;&amp;amp;[ "$Char" = "Y" ];then&lt;BR /&gt;    echo "num &amp;lt; 5 and char is : 'Y'"&lt;BR /&gt;else&lt;BR /&gt;    echo "num &amp;gt; 5 and char is : 'N'"&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;-NKG-</description>
      <pubDate>Tue, 18 Nov 2008 06:11:54 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/nested-if-else-statement/m-p/4307424#M338849</guid>
      <dc:creator>Nitin Kumar Gupta</dc:creator>
      <dc:date>2008-11-18T06:11:54Z</dc:date>
    </item>
    <item>
      <title>Re: nested if else statement</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/nested-if-else-statement/m-p/4307425#M338850</link>
      <description>Hi Dennis/Nitin,&lt;BR /&gt;&lt;BR /&gt;Many thanks,&lt;BR /&gt;&lt;BR /&gt;I got solution first from Deninis reply.&lt;BR /&gt;&lt;BR /&gt;Also thanks Nitin for expaling very nicely.&lt;BR /&gt;&lt;BR /&gt;Thanks</description>
      <pubDate>Tue, 18 Nov 2008 08:15:26 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/nested-if-else-statement/m-p/4307425#M338850</guid>
      <dc:creator>diwakar_4</dc:creator>
      <dc:date>2008-11-18T08:15:26Z</dc:date>
    </item>
    <item>
      <title>Re: nested if else statement</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/nested-if-else-statement/m-p/4307426#M338851</link>
      <description>Nitin,&lt;BR /&gt;I would not use the -eq num method.&lt;BR /&gt;If he needs to do this with a greater amount of numbers then 3 it'd be a pain and a long long line.&lt;BR /&gt;&lt;BR /&gt;It's better to use greater and lesser then comparision.&lt;BR /&gt;&lt;BR /&gt;if [ $Num -ge 0 -a $Num -le 2 ]; then&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;Also the string comparision operator is not =, it's ==. Also a note for diwakar, don't forget the encapsulation with "".&lt;BR /&gt;&lt;BR /&gt;if [ "$Char" == "Y" ]; then&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;Best regards&lt;BR /&gt;Fredrik Eriksson</description>
      <pubDate>Tue, 18 Nov 2008 08:20:35 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/nested-if-else-statement/m-p/4307426#M338851</guid>
      <dc:creator>Fredrik.eriksson</dc:creator>
      <dc:date>2008-11-18T08:20:35Z</dc:date>
    </item>
    <item>
      <title>Re: nested if else statement</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/nested-if-else-statement/m-p/4307427#M338852</link>
      <description>&amp;gt;Fredrik: Also the string comparison operator is not =, it's ==.&lt;BR /&gt;&lt;BR /&gt;This is not the case in a real shell.  == is only valid for arithmetic expressions (( )).&lt;BR /&gt;(Unless this is new for ksh 93?)</description>
      <pubDate>Tue, 18 Nov 2008 11:04:19 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/nested-if-else-statement/m-p/4307427#M338852</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2008-11-18T11:04:19Z</dc:date>
    </item>
  </channel>
</rss>

