<?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: Can not seem to get this IF statement to work in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/can-not-seem-to-get-this-if-statement-to-work/m-p/4876445#M707966</link>
    <description>Scott,&lt;BR /&gt;&lt;BR /&gt;Isn't this similar to the problem you had a while back:&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=737698" target="_blank"&gt;http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=737698&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;To quote Clay, "The problem is that the shell only does integer arithmetic. Use awk or bc."&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Pete</description>
    <pubDate>Tue, 21 Dec 2004 13:25:08 GMT</pubDate>
    <dc:creator>Pete Randall</dc:creator>
    <dc:date>2004-12-21T13:25:08Z</dc:date>
    <item>
      <title>Can not seem to get this IF statement to work</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/can-not-seem-to-get-this-if-statement-to-work/m-p/4876441#M707962</link>
      <description>I have three variables&lt;BR /&gt;$WCPU = 0.48&lt;BR /&gt;$HIGHWATER 0.10&lt;BR /&gt;$COUNTER 1&lt;BR /&gt;I want to do something like this&lt;BR /&gt;If $WCPU is greater than or equal to $HIGHWATER AND $COUNTER is equal to 0 then do something.&lt;BR /&gt;&lt;BR /&gt;I've tried if [$WCPU -ge $HIGHWATER -a $COUNTER -eq 0] but it doesn't work.  I get&lt;BR /&gt;./toptest.sh[23]: [0.48:  not found.</description>
      <pubDate>Tue, 21 Dec 2004 13:05:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/can-not-seem-to-get-this-if-statement-to-work/m-p/4876441#M707962</guid>
      <dc:creator>Scott Frye_1</dc:creator>
      <dc:date>2004-12-21T13:05:20Z</dc:date>
    </item>
    <item>
      <title>Re: Can not seem to get this IF statement to work</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/can-not-seem-to-get-this-if-statement-to-work/m-p/4876442#M707963</link>
      <description>When using -ge, you need double brackets, also whitespace.&lt;BR /&gt;&lt;BR /&gt;Try [[ $WCPU -ge $HIGHWATER -a $COUNTER -eq 0 ]]</description>
      <pubDate>Tue, 21 Dec 2004 13:14:16 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/can-not-seem-to-get-this-if-statement-to-work/m-p/4876442#M707963</guid>
      <dc:creator>Scot Bean</dc:creator>
      <dc:date>2004-12-21T13:14:16Z</dc:date>
    </item>
    <item>
      <title>Re: Can not seem to get this IF statement to work</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/can-not-seem-to-get-this-if-statement-to-work/m-p/4876443#M707964</link>
      <description>Leave a space between the brackets and the characters inside, like this:&lt;BR /&gt;&lt;BR /&gt;if [ $WCPU -ge $HIGHWATER -a $COUNTER -eq 0 ]&lt;BR /&gt;&lt;BR /&gt;From your error message, it appears the shell is trying to evaluate [$WCPU as a command.&lt;BR /&gt;&lt;BR /&gt;Also, AFAIK, ksh can only handle integers in variables for purposes of determining greater than and less than. It will evaluate 0.48 and 0.10 as 0 in the if statement. You may want to change your numbering to use integers instead.&lt;BR /&gt;&lt;BR /&gt;-JWJ&lt;BR /&gt;</description>
      <pubDate>Tue, 21 Dec 2004 13:14:19 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/can-not-seem-to-get-this-if-statement-to-work/m-p/4876443#M707964</guid>
      <dc:creator>Jerry Jordak</dc:creator>
      <dc:date>2004-12-21T13:14:19Z</dc:date>
    </item>
    <item>
      <title>Re: Can not seem to get this IF statement to work</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/can-not-seem-to-get-this-if-statement-to-work/m-p/4876444#M707965</link>
      <description>Jerry,&lt;BR /&gt;&lt;BR /&gt;What are you suggesting I do with my variables?</description>
      <pubDate>Tue, 21 Dec 2004 13:22:03 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/can-not-seem-to-get-this-if-statement-to-work/m-p/4876444#M707965</guid>
      <dc:creator>Scott Frye_1</dc:creator>
      <dc:date>2004-12-21T13:22:03Z</dc:date>
    </item>
    <item>
      <title>Re: Can not seem to get this IF statement to work</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/can-not-seem-to-get-this-if-statement-to-work/m-p/4876445#M707966</link>
      <description>Scott,&lt;BR /&gt;&lt;BR /&gt;Isn't this similar to the problem you had a while back:&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=737698" target="_blank"&gt;http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=737698&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;To quote Clay, "The problem is that the shell only does integer arithmetic. Use awk or bc."&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Pete</description>
      <pubDate>Tue, 21 Dec 2004 13:25:08 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/can-not-seem-to-get-this-if-statement-to-work/m-p/4876445#M707966</guid>
      <dc:creator>Pete Randall</dc:creator>
      <dc:date>2004-12-21T13:25:08Z</dc:date>
    </item>
    <item>
      <title>Re: Can not seem to get this IF statement to work</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/can-not-seem-to-get-this-if-statement-to-work/m-p/4876446#M707967</link>
      <description>In cases like this, where I know I might have numbers with values between 0 and 1, I've multiplied the values of the variables by 100, so that the if statements will work properly.&lt;BR /&gt;&lt;BR /&gt;For example, if you define the variables as so:&lt;BR /&gt;&lt;BR /&gt;WCPU=48&lt;BR /&gt;HIGHWATER=10&lt;BR /&gt;&lt;BR /&gt;then it will work. If you're getting the $WCPU value from another command or a script, you may need to convert it, by removing the decimal point.</description>
      <pubDate>Tue, 21 Dec 2004 13:28:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/can-not-seem-to-get-this-if-statement-to-work/m-p/4876446#M707967</guid>
      <dc:creator>Jerry Jordak</dc:creator>
      <dc:date>2004-12-21T13:28:32Z</dc:date>
    </item>
    <item>
      <title>Re: Can not seem to get this IF statement to work</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/can-not-seem-to-get-this-if-statement-to-work/m-p/4876447#M707968</link>
      <description>Pete,&lt;BR /&gt;&lt;BR /&gt;I believe that is in the same ball park.  I had forgetten about that thread.  I quickly manned bc and I found it does not currently support &amp;amp;&amp;amp; or ||.  Also, I'm not clear on it usage in my if statement.&lt;BR /&gt;&lt;BR /&gt;If you have done anything like this before, I would enjoy seeing some examples.&lt;BR /&gt;&lt;BR /&gt;Thanks again for refreshing my memory.&lt;BR /&gt;&lt;BR /&gt;Scott</description>
      <pubDate>Tue, 21 Dec 2004 13:32:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/can-not-seem-to-get-this-if-statement-to-work/m-p/4876447#M707968</guid>
      <dc:creator>Scott Frye_1</dc:creator>
      <dc:date>2004-12-21T13:32:15Z</dc:date>
    </item>
    <item>
      <title>Re: Can not seem to get this IF statement to work</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/can-not-seem-to-get-this-if-statement-to-work/m-p/4876448#M707969</link>
      <description>Scott,&lt;BR /&gt;&lt;BR /&gt;I'm not all that great on shell scripting myself - I only stumbled over that thread while I was searching the ITRC for a solution to your problem.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Pete</description>
      <pubDate>Tue, 21 Dec 2004 13:38:07 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/can-not-seem-to-get-this-if-statement-to-work/m-p/4876448#M707969</guid>
      <dc:creator>Pete Randall</dc:creator>
      <dc:date>2004-12-21T13:38:07Z</dc:date>
    </item>
    <item>
      <title>Re: Can not seem to get this IF statement to work</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/can-not-seem-to-get-this-if-statement-to-work/m-p/4876449#M707970</link>
      <description>Scott,&lt;BR /&gt;&lt;BR /&gt;if you format wcpu and highwater the same way you can compare them as strings.&lt;BR /&gt;WCPU=`printf %06.2f 0.48`&lt;BR /&gt;HIGHWATER==`printf %06.2f 0.10`&lt;BR /&gt;if [ "$WCPU" &amp;gt; "$HIGHWATER" ]..&lt;BR /&gt;&lt;BR /&gt;greetings,&lt;BR /&gt;&lt;BR /&gt;Michael&lt;BR /&gt;</description>
      <pubDate>Tue, 21 Dec 2004 14:31:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/can-not-seem-to-get-this-if-statement-to-work/m-p/4876449#M707970</guid>
      <dc:creator>Michael Schulte zur Sur</dc:creator>
      <dc:date>2004-12-21T14:31:15Z</dc:date>
    </item>
    <item>
      <title>Re: Can not seem to get this IF statement to work</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/can-not-seem-to-get-this-if-statement-to-work/m-p/4876450#M707971</link>
      <description>As others have pointed out, ksh only does integer math.  You can fix your numbers with:&lt;BR /&gt;NCPU=(( "$WCPU" * "100" ))&lt;BR /&gt;NHIGHWATER=(( "$HIGHWATER" * "100" ))&lt;BR /&gt;if test "$NHIGHWATER" -eq "$NCPU" -a "$COUNTER1" -eq "0"&lt;BR /&gt;then&lt;BR /&gt;               do something&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;The double parenthesis is ksh's version of the "let" statement.&lt;BR /&gt;</description>
      <pubDate>Tue, 21 Dec 2004 17:52:10 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/can-not-seem-to-get-this-if-statement-to-work/m-p/4876450#M707971</guid>
      <dc:creator>Chris Vail</dc:creator>
      <dc:date>2004-12-21T17:52:10Z</dc:date>
    </item>
    <item>
      <title>Re: Can not seem to get this IF statement to work</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/can-not-seem-to-get-this-if-statement-to-work/m-p/4876451#M707972</link>
      <description>NCPU=(( "$WCPU" * "100" ))&lt;BR /&gt;is going to evaluate as 0 if ${WCPU} is 0.48)&lt;BR /&gt;&lt;BR /&gt;Here's a method to leverage bc for the floating-point evaluation. It will return 1 if ${WCPU} &amp;gt;= ${HIGHWATER} and 0 otherwise.&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;&lt;BR /&gt;WCPU=0.48&lt;BR /&gt;HIGHWATER=0.10&lt;BR /&gt;COUNTER=1&lt;BR /&gt;&lt;BR /&gt;typeset -i A=$(echo "a = 0; if (${WCPU} &amp;gt;= ${HIGHWATER}) a = 1;a" | bc)&lt;BR /&gt;# now we can do a compound if&lt;BR /&gt;if [[ ${A} -ne 0 &amp;amp;&amp;amp; ${COUNTER} -eq 0 ]]&lt;BR /&gt;  then&lt;BR /&gt;    echo "Do your thing"&lt;BR /&gt;  fi&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 21 Dec 2004 18:13:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/can-not-seem-to-get-this-if-statement-to-work/m-p/4876451#M707972</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2004-12-21T18:13:52Z</dc:date>
    </item>
    <item>
      <title>Re: Can not seem to get this IF statement to work</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/can-not-seem-to-get-this-if-statement-to-work/m-p/4876452#M707973</link>
      <description>Clay,&lt;BR /&gt;&lt;BR /&gt;your routine does not work if for example&lt;BR /&gt;WCPU=10.10&lt;BR /&gt;HIGHWATER=4.1&lt;BR /&gt;&lt;BR /&gt;It seems that not every shell supports string1 &amp;gt; string2 comparisons.&lt;BR /&gt;&lt;BR /&gt;Inspired of Chris another try:&lt;BR /&gt;#!/usr/bin/sh -x&lt;BR /&gt;WCPU=`eval echo 0.08 | awk '{printf("%06.2f",$1*100)}'`&lt;BR /&gt;HIGHWATER=`eval echo 0.18 | awk '{printf("%06.2f",$1*100)}'`&lt;BR /&gt;if test ${WCPU} -gt ${HIGHWATER}&lt;BR /&gt;then&lt;BR /&gt;  echo do your thing&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;greetings,&lt;BR /&gt;&lt;BR /&gt;Michael&lt;BR /&gt;</description>
      <pubDate>Wed, 22 Dec 2004 07:27:49 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/can-not-seem-to-get-this-if-statement-to-work/m-p/4876452#M707973</guid>
      <dc:creator>Michael Schulte zur Sur</dc:creator>
      <dc:date>2004-12-22T07:27:49Z</dc:date>
    </item>
    <item>
      <title>Re: Can not seem to get this IF statement to work</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/can-not-seem-to-get-this-if-statement-to-work/m-p/4876453#M707974</link>
      <description>Thank you to all who posted to this thread.  Although I'm not quite clear what it is doing yet (I love learning this way), I'm going to take Clay's approach.&lt;BR /&gt;&lt;BR /&gt;Thanks again to all.</description>
      <pubDate>Wed, 22 Dec 2004 08:25:01 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/can-not-seem-to-get-this-if-statement-to-work/m-p/4876453#M707974</guid>
      <dc:creator>Scott Frye_1</dc:creator>
      <dc:date>2004-12-22T08:25:01Z</dc:date>
    </item>
  </channel>
</rss>

