<?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: Small Script - not working for decimals in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/small-script-not-working-for-decimals/m-p/3756539#M258563</link>
    <description>Hi,&lt;BR /&gt;&lt;BR /&gt;maybe I am missing it too, but I do not think that a comparison is an arithmetic operation....&lt;BR /&gt;&lt;BR /&gt;regards,&lt;BR /&gt;John K.&lt;BR /&gt;</description>
    <pubDate>Wed, 22 Mar 2006 08:17:03 GMT</pubDate>
    <dc:creator>john korterman</dc:creator>
    <dc:date>2006-03-22T08:17:03Z</dc:date>
    <item>
      <title>Small Script - not working for decimals</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/small-script-not-working-for-decimals/m-p/3756534#M258558</link>
      <description>Hi Admins,&lt;BR /&gt;&lt;BR /&gt; I hav just born new to scriptings. I tried comparing 2 digits and execute the bigger one. Hereby the script i made :&lt;BR /&gt;&lt;BR /&gt;#! /sbin/sh&lt;BR /&gt;echo "Type any Number"&lt;BR /&gt;read a&lt;BR /&gt;echo "Type another Number"&lt;BR /&gt;read b&lt;BR /&gt;clear&lt;BR /&gt;echo&lt;BR /&gt;if [ $a -gt $b ]&lt;BR /&gt;then&lt;BR /&gt;echo Greater Number is $a&lt;BR /&gt;else&lt;BR /&gt;echo Greater Number is $b&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;  This works fine for all integers but not for decimals. Can anybody help me out. &lt;BR /&gt;&lt;BR /&gt;Regds,&lt;BR /&gt; Just - In</description>
      <pubDate>Wed, 22 Mar 2006 07:14:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/small-script-not-working-for-decimals/m-p/3756534#M258558</guid>
      <dc:creator>Justin_132</dc:creator>
      <dc:date>2006-03-22T07:14:31Z</dc:date>
    </item>
    <item>
      <title>Re: Small Script - not working for decimals</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/small-script-not-working-for-decimals/m-p/3756535#M258559</link>
      <description>Shells do not do any decimal/fraction calculations. You will have to use bc/dc for that.</description>
      <pubDate>Wed, 22 Mar 2006 07:20:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/small-script-not-working-for-decimals/m-p/3756535#M258559</guid>
      <dc:creator>RAC_1</dc:creator>
      <dc:date>2006-03-22T07:20:20Z</dc:date>
    </item>
    <item>
      <title>Re: Small Script - not working for decimals</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/small-script-not-working-for-decimals/m-p/3756536#M258560</link>
      <description>Hi Justin:&lt;BR /&gt;&lt;BR /&gt;The standard shells, as noted, do decimal arithmetic, so you have to resort to other means.  One way is to leverage 'awk':&lt;BR /&gt;&lt;BR /&gt;# echo "1.1 1.3"|awk '{if ($1 &amp;gt;= $2) {print $1 " geq " $2} else {print $2 " lss " $1}}'&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Wed, 22 Mar 2006 07:32:13 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/small-script-not-working-for-decimals/m-p/3756536#M258560</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2006-03-22T07:32:13Z</dc:date>
    </item>
    <item>
      <title>Re: Small Script - not working for decimals</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/small-script-not-working-for-decimals/m-p/3756537#M258561</link>
      <description>Hi Justin:&lt;BR /&gt;&lt;BR /&gt;Sorry, I scrambled the output a bit on the last post.  It is also good form to force 'awk' to convert its strings to numbers by adding '0':&lt;BR /&gt;&lt;BR /&gt;# echo "1.01 1.003" | awk '{if (($1+0) &amp;gt;= ($2+0)) {print $1 " geq " $2} else {print $1 " lss " $2}}'  &lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Wed, 22 Mar 2006 07:59:34 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/small-script-not-working-for-decimals/m-p/3756537#M258561</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2006-03-22T07:59:34Z</dc:date>
    </item>
    <item>
      <title>Re: Small Script - not working for decimals</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/small-script-not-working-for-decimals/m-p/3756538#M258562</link>
      <description>Hi Admins,&lt;BR /&gt;&lt;BR /&gt; Im really surprised what RAC said, but the below script wrks finding less/greater than 1.&lt;BR /&gt;&lt;BR /&gt;#! /sbin/sh&lt;BR /&gt;echo "Type any Number"&lt;BR /&gt;read a&lt;BR /&gt;#echo "Type another Number"&lt;BR /&gt;#read b&lt;BR /&gt;clear&lt;BR /&gt;if [ $a -gt 1 ]&lt;BR /&gt;then&lt;BR /&gt;echo The Number $a is Greater than 1&lt;BR /&gt;else&lt;BR /&gt;echo The Number $a is Lesser than 1&lt;BR /&gt;echo&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt; Where am I missing something, or What I should I do to make this work..&lt;BR /&gt;&lt;BR /&gt;Regds,&lt;BR /&gt;Just - In</description>
      <pubDate>Wed, 22 Mar 2006 08:04:29 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/small-script-not-working-for-decimals/m-p/3756538#M258562</guid>
      <dc:creator>Justin_132</dc:creator>
      <dc:date>2006-03-22T08:04:29Z</dc:date>
    </item>
    <item>
      <title>Re: Small Script - not working for decimals</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/small-script-not-working-for-decimals/m-p/3756539#M258563</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;maybe I am missing it too, but I do not think that a comparison is an arithmetic operation....&lt;BR /&gt;&lt;BR /&gt;regards,&lt;BR /&gt;John K.&lt;BR /&gt;</description>
      <pubDate>Wed, 22 Mar 2006 08:17:03 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/small-script-not-working-for-decimals/m-p/3756539#M258563</guid>
      <dc:creator>john korterman</dc:creator>
      <dc:date>2006-03-22T08:17:03Z</dc:date>
    </item>
    <item>
      <title>Re: Small Script - not working for decimals</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/small-script-not-working-for-decimals/m-p/3756540#M258564</link>
      <description>&lt;BR /&gt;&lt;BR /&gt;&amp;gt;&amp;gt; I hav just born new to scriptings&lt;BR /&gt;&lt;BR /&gt;Don't go there! Learn perl insteead.&lt;BR /&gt;&lt;BR /&gt;&amp;gt;&amp;gt; Im really surprised what RAC said&lt;BR /&gt;&lt;BR /&gt;Well, you indicated you are new to scripting. RAC (and JRF) have been around the block once or twice.&lt;BR /&gt;Hmmm... where would I put money.&lt;BR /&gt;&lt;BR /&gt;&amp;gt;&amp;gt; but the below script wrks finding less/greater than 1.&lt;BR /&gt;&lt;BR /&gt;It just 'happens' to work.&lt;BR /&gt;It's still wrong.&lt;BR /&gt;&lt;BR /&gt;Hint: google for: +shell +unix +decimal +fractions&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Kindest regards,&lt;BR /&gt;Hein.&lt;BR /&gt;&lt;BR /&gt;(we should redefine '2 points' as: The answer was correct, but it is not what I wanted to hear. )&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 22 Mar 2006 08:26:56 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/small-script-not-working-for-decimals/m-p/3756540#M258564</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2006-03-22T08:26:56Z</dc:date>
    </item>
    <item>
      <title>Re: Small Script - not working for decimals</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/small-script-not-working-for-decimals/m-p/3756541#M258565</link>
      <description>Hi (again) Justin:&lt;BR /&gt;&lt;BR /&gt;Well, compare your script (as originally written in your opening post) with the 'awk' code I offered:&lt;BR /&gt;&lt;BR /&gt;# ./testsh&lt;BR /&gt;Type any Number&lt;BR /&gt;.3&lt;BR /&gt;Type another Number&lt;BR /&gt;0.1&lt;BR /&gt;Greater Number is 0.1&lt;BR /&gt;&lt;BR /&gt;...really!?!&lt;BR /&gt;&lt;BR /&gt;# echo ".3 0.1"|awk '{if (($1+0) &amp;gt;= ($2+0)) {print $1 " geq " $2} else {print $1 " lss " $2}}'&lt;BR /&gt;.3 geq 0.1&lt;BR /&gt;#&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Wed, 22 Mar 2006 09:21:26 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/small-script-not-working-for-decimals/m-p/3756541#M258565</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2006-03-22T09:21:26Z</dc:date>
    </item>
    <item>
      <title>Re: Small Script - not working for decimals</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/small-script-not-working-for-decimals/m-p/3756542#M258566</link>
      <description>Hi (again) Justin:&lt;BR /&gt;&lt;BR /&gt;At the onset of this discussion I said that many shells only do decimal arithmetic.  More modern versions of the Korn shell offer real number arithmetic, however.  You have a Korn93 version available and this will help if you want to use it.&lt;BR /&gt;&lt;BR /&gt;Change the first three lines of your original script to this:&lt;BR /&gt;&lt;BR /&gt;#!/usr/dt/bin/dtksh&lt;BR /&gt;typeset -E  a&lt;BR /&gt;typeset -E  b&lt;BR /&gt;&lt;BR /&gt;Now compare this version using ".3" and "0.1" as the input numbers.&lt;BR /&gt;&lt;BR /&gt;In passing, I noted that when you used the standard Posix shell you used the statically-linked version found in '/sbin' as opposed to the dynamically linked '/usr/bin'.&lt;BR /&gt;&lt;BR /&gt;For general use, '/usr/bin' is preferred since use of dynamic libraries reduces its memory footprint.  For startup scripts, as root, you *must* use the '/sbin' version since '/usr' isn't mounted in the early stages of startup.&lt;BR /&gt;&lt;BR /&gt;I caution you about this so you don't capriciously start using the Korn shell in '/usr/dt/bin' thinking that its an answer to all your problems!&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;</description>
      <pubDate>Wed, 22 Mar 2006 09:43:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/small-script-not-working-for-decimals/m-p/3756542#M258566</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2006-03-22T09:43:31Z</dc:date>
    </item>
    <item>
      <title>Re: Small Script - not working for decimals</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/small-script-not-working-for-decimals/m-p/3756543#M258567</link>
      <description>By default neither ksh88 or the POSIX shell support float types or variables. So if you need to use decimals you have a couple of options:&lt;BR /&gt;* Use dtksh, which is based on ksh93 which does support floats&lt;BR /&gt;* Use an external program, e.g. bc, dc or awk:&lt;BR /&gt;  echo "4.5 + 6.7" | bc&lt;BR /&gt;* An old technique to keep it in shell, is to multiply all numbers by a fixed value (e.g. if you want 2 decimal places, use 100), so we have:&lt;BR /&gt;  Fred=450&lt;BR /&gt;  Jim=670&lt;BR /&gt;  Shelia=$(( Fred + Jim ))&lt;BR /&gt;  echo "$((Shelia / 100)).$((Shelia % 100))</description>
      <pubDate>Wed, 22 Mar 2006 13:03:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/small-script-not-working-for-decimals/m-p/3756543#M258567</guid>
      <dc:creator>David Lodge</dc:creator>
      <dc:date>2006-03-22T13:03:45Z</dc:date>
    </item>
    <item>
      <title>Re: Small Script - not working for decimals</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/small-script-not-working-for-decimals/m-p/3756544#M258568</link>
      <description>Hi Justin,&lt;BR /&gt;&lt;BR /&gt;Not sure how your script is working since the shell will be doing a lexicographic comparison based on the ASCII character set. Fortunately the "-", 0 are numerically &amp;lt; than 1 while 2 thru 9 characters are numerically &amp;gt; than 1 in the ASCII character set, with the exception of the period. That said your script will give erroneous results for decimal digits between 1 and 2 for ex. 1.5.&lt;BR /&gt;&lt;BR /&gt;hope it helps!</description>
      <pubDate>Wed, 22 Mar 2006 13:40:51 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/small-script-not-working-for-decimals/m-p/3756544#M258568</guid>
      <dc:creator>Sandman!</dc:creator>
      <dc:date>2006-03-22T13:40:51Z</dc:date>
    </item>
    <item>
      <title>Re: Small Script - not working for decimals</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/small-script-not-working-for-decimals/m-p/3756545#M258569</link>
      <description>Hi Just-in (this enjoy myself a lot!)&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;In UNIX shell arithmetic comparison &lt;BR /&gt;is limited to integer values.  Here &lt;BR /&gt;is a tip to compare floating values &lt;BR /&gt;using basic shell commands.&lt;BR /&gt;&lt;BR /&gt;--------- CUT HERE-----------------&lt;BR /&gt;&lt;BR /&gt;#! /bin/sh&lt;BR /&gt;# test shell script&lt;BR /&gt;n1="01.401"&lt;BR /&gt;n2="01.350"&lt;BR /&gt;&lt;BR /&gt;function compareFloatSmall&lt;BR /&gt;{&lt;BR /&gt;sort -n &amp;lt;&amp;lt;: | head -1&lt;BR /&gt;$n1&lt;BR /&gt;$n2&lt;BR /&gt;:&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;function compareFloatGreat&lt;BR /&gt;{&lt;BR /&gt;sort -r -n &amp;lt;&amp;lt;: | head -1&lt;BR /&gt;$n1&lt;BR /&gt;$n2&lt;BR /&gt;:&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;small=$(compareFloatSmall $n1 $n2)&lt;BR /&gt;echo "Comparing $n1 to $n2: smaller $less"&lt;BR /&gt;great=$(compareFloatGreat $n1 $n2)&lt;BR /&gt;echo "Comparing $n1 to $n2: greater $great"&lt;BR /&gt;&lt;BR /&gt;--------- CUT HERE-----------------&lt;BR /&gt;&lt;BR /&gt;Alternatively you can use a small 'awk' program.&lt;BR /&gt;&lt;BR /&gt;--------- CUT AGAIN HERE-----------&lt;BR /&gt;#! /bin/sh&lt;BR /&gt;# A couple of examples in awk.&lt;BR /&gt;n1="03.550"&lt;BR /&gt;n2="02.550"&lt;BR /&gt;&lt;BR /&gt;echo "$n1 $n2" | awk '{&lt;BR /&gt;        if ( $1 &amp;gt;= $2 ) print $1&lt;BR /&gt;        if ( $1 &amp;lt;= $2 ) print $2&lt;BR /&gt;        if ( $1 &amp;gt;  $2 ) print $1&lt;BR /&gt;        if ( $1 &amp;lt;  $2 ) print $2&lt;BR /&gt;        if ( $1 == $2 ) print $1, $2&lt;BR /&gt;}'&lt;BR /&gt;--------- CUT AGAIN HERE-----------&lt;BR /&gt;&lt;BR /&gt;HTH,&lt;BR /&gt;Art&lt;BR /&gt;</description>
      <pubDate>Thu, 23 Mar 2006 04:34:28 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/small-script-not-working-for-decimals/m-p/3756545#M258569</guid>
      <dc:creator>Arturo Galbiati</dc:creator>
      <dc:date>2006-03-23T04:34:28Z</dc:date>
    </item>
  </channel>
</rss>

