<?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: Addition in Shell Script in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/addition-in-shell-script/m-p/3153905#M884802</link>
    <description>Hi,&lt;BR /&gt;Just an addition to John Palmers reply.&lt;BR /&gt;&lt;BR /&gt;There is actually a modulus operator in ksh (modulus= the rest in an integer division).&lt;BR /&gt;&lt;BR /&gt;try the following:&lt;BR /&gt;&lt;BR /&gt;let iii=count/100&lt;BR /&gt;&lt;BR /&gt;let ddd=count%100&lt;BR /&gt;&lt;BR /&gt;print ${iii}.${ddd}&lt;BR /&gt;</description>
    <pubDate>Tue, 30 Dec 2003 12:57:03 GMT</pubDate>
    <dc:creator>Leif Halvarsson_2</dc:creator>
    <dc:date>2003-12-30T12:57:03Z</dc:date>
    <item>
      <title>Addition in Shell Script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/addition-in-shell-script/m-p/3153899#M884796</link>
      <description>I have the following requirement for a shell script:&lt;BR /&gt;&lt;BR /&gt;count=555.07&lt;BR /&gt;&lt;BR /&gt;I want count to increment by ".01" based on my needs at a given time.  I tried using some variations with "expr" to make the next count "555.08" in this example, but it does not seem to like the ".##".  It returns the error "expr: An integer value was expected." When I do it with 555 and add 1, it works great. &lt;BR /&gt;&lt;BR /&gt;Please let me know if I need some quoutes in special places or if I should be using something else besides expr...&lt;BR /&gt;&lt;BR /&gt;Thanks for you help!</description>
      <pubDate>Tue, 30 Dec 2003 09:59:38 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/addition-in-shell-script/m-p/3153899#M884796</guid>
      <dc:creator>Ryan B</dc:creator>
      <dc:date>2003-12-30T09:59:38Z</dc:date>
    </item>
    <item>
      <title>Re: Addition in Shell Script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/addition-in-shell-script/m-p/3153900#M884797</link>
      <description>The Korn/Posix shell is only capable of integer arithmetic. It can do this internally without the need for 'expr' which being an external command is relatively inefficient.&lt;BR /&gt;&lt;BR /&gt;It may be possible to achieve what you want using integer arithmetic but you'll have to program around it. If you want 2 places of decimals then you'll have to work with your number multiplied by 100 (in your case 55507).&lt;BR /&gt;&lt;BR /&gt;Something like this:-&lt;BR /&gt;&lt;BR /&gt;typeset -i10 count iii ddd&lt;BR /&gt;typeset -Z2 ddd&lt;BR /&gt;&lt;BR /&gt;let count=55507&lt;BR /&gt;let count=count+1&lt;BR /&gt;&lt;BR /&gt;To display count as a real number you will have to seperate it into two parts. The integer part is easy:-&lt;BR /&gt;&lt;BR /&gt;let iii=count/100&lt;BR /&gt;&lt;BR /&gt;The decimal part is a bit harder:-&lt;BR /&gt;let ddd="count-(100*iii)"&lt;BR /&gt;&lt;BR /&gt;You can then print it with:&lt;BR /&gt;print ${iii}.${ddd}&lt;BR /&gt;&lt;BR /&gt;The typeset -Z2 ddd ensures that $ddd has a leading zero when it has a value less than 10 as in your case.&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;John</description>
      <pubDate>Tue, 30 Dec 2003 10:38:19 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/addition-in-shell-script/m-p/3153900#M884797</guid>
      <dc:creator>John Palmer</dc:creator>
      <dc:date>2003-12-30T10:38:19Z</dc:date>
    </item>
    <item>
      <title>Re: Addition in Shell Script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/addition-in-shell-script/m-p/3153901#M884798</link>
      <description>what about perl ?&lt;BR /&gt;&lt;BR /&gt;count=`perl -e 'print $ARGV[0]  + 0.01' $count`&lt;BR /&gt;&lt;BR /&gt;another good idea would be to set count to 55507 and increase it by 1 during each loop.&lt;BR /&gt;&lt;BR /&gt;Best regards&lt;BR /&gt;&lt;BR /&gt;Stefan</description>
      <pubDate>Tue, 30 Dec 2003 10:50:10 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/addition-in-shell-script/m-p/3153901#M884798</guid>
      <dc:creator>Stefan Stechemesser</dc:creator>
      <dc:date>2003-12-30T10:50:10Z</dc:date>
    </item>
    <item>
      <title>Re: Addition in Shell Script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/addition-in-shell-script/m-p/3153902#M884799</link>
      <description>The expr command can perform simple integer operations. For floating point arithmetic, the awk or bc utilities can be used.&lt;BR /&gt;&lt;BR /&gt;HTH,&lt;BR /&gt;Elena.</description>
      <pubDate>Tue, 30 Dec 2003 10:50:17 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/addition-in-shell-script/m-p/3153902#M884799</guid>
      <dc:creator>Elena Leontieva</dc:creator>
      <dc:date>2003-12-30T10:50:17Z</dc:date>
    </item>
    <item>
      <title>Re: Addition in Shell Script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/addition-in-shell-script/m-p/3153903#M884800</link>
      <description>awk also does a good job with floating point values...&lt;BR /&gt;&lt;BR /&gt;Here's an example of something you could test with quickly.&lt;BR /&gt;&lt;BR /&gt;Create a dummy file 'grades' that looks like this:&lt;BR /&gt;&lt;BR /&gt;You 100 99.8  69.4&lt;BR /&gt;Me 99.2 78.9 88.3&lt;BR /&gt;Other 84.3 96.21 90.33&lt;BR /&gt;&lt;BR /&gt;Now create a dummy awk script that just says something like:&lt;BR /&gt;&lt;BR /&gt;awk '{ sum =$2 + $3 + $4 ; avg = sum / 3&lt;BR /&gt;     print $1, avg }' grades&lt;BR /&gt;&lt;BR /&gt;Run the dummy awk script and you will see that it added the grades and calculated the avg grade for each and prints it....floating point and all.&lt;BR /&gt;&lt;BR /&gt;Rgrds,&lt;BR /&gt;....I luv awk....&lt;BR /&gt;Rita&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 30 Dec 2003 11:02:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/addition-in-shell-script/m-p/3153903#M884800</guid>
      <dc:creator>Rita C Workman</dc:creator>
      <dc:date>2003-12-30T11:02:31Z</dc:date>
    </item>
    <item>
      <title>Re: Addition in Shell Script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/addition-in-shell-script/m-p/3153904#M884801</link>
      <description>1) you could use a shell that supports floating point numbers&lt;BR /&gt;&lt;BR /&gt;#!/usr/dt/bin/dtksh&lt;BR /&gt;&lt;BR /&gt;typeset -F inc=.01 count&lt;BR /&gt;&lt;BR /&gt;count=555.07&lt;BR /&gt;count=$(( $count + $inc ))&lt;BR /&gt;print $count&lt;BR /&gt;&lt;BR /&gt;or use bc as a co process&lt;BR /&gt;&lt;BR /&gt;count=555.07&lt;BR /&gt;# This starts bc with a two-way pipe &lt;BR /&gt;bc |&amp;amp; &lt;BR /&gt;# print -p writes to the pipe &lt;BR /&gt;print -p "$count + .01"&lt;BR /&gt;# read -p reads from the pipe &lt;BR /&gt;read -p count &lt;BR /&gt;print $count &lt;BR /&gt;</description>
      <pubDate>Tue, 30 Dec 2003 11:45:02 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/addition-in-shell-script/m-p/3153904#M884801</guid>
      <dc:creator>curt larson_1</dc:creator>
      <dc:date>2003-12-30T11:45:02Z</dc:date>
    </item>
    <item>
      <title>Re: Addition in Shell Script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/addition-in-shell-script/m-p/3153905#M884802</link>
      <description>Hi,&lt;BR /&gt;Just an addition to John Palmers reply.&lt;BR /&gt;&lt;BR /&gt;There is actually a modulus operator in ksh (modulus= the rest in an integer division).&lt;BR /&gt;&lt;BR /&gt;try the following:&lt;BR /&gt;&lt;BR /&gt;let iii=count/100&lt;BR /&gt;&lt;BR /&gt;let ddd=count%100&lt;BR /&gt;&lt;BR /&gt;print ${iii}.${ddd}&lt;BR /&gt;</description>
      <pubDate>Tue, 30 Dec 2003 12:57:03 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/addition-in-shell-script/m-p/3153905#M884802</guid>
      <dc:creator>Leif Halvarsson_2</dc:creator>
      <dc:date>2003-12-30T12:57:03Z</dc:date>
    </item>
    <item>
      <title>Re: Addition in Shell Script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/addition-in-shell-script/m-p/3153906#M884803</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;try this:&lt;BR /&gt;COUNT=1&lt;BR /&gt;COUNT=`echo 0.01 + ${COUNT}|bc`&lt;BR /&gt;&lt;BR /&gt;greetings,&lt;BR /&gt;&lt;BR /&gt;Michael&lt;BR /&gt;</description>
      <pubDate>Tue, 30 Dec 2003 13:46:17 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/addition-in-shell-script/m-p/3153906#M884803</guid>
      <dc:creator>Michael Schulte zur Sur</dc:creator>
      <dc:date>2003-12-30T13:46:17Z</dc:date>
    </item>
    <item>
      <title>Re: Addition in Shell Script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/addition-in-shell-script/m-p/3153907#M884806</link>
      <description>Wow, thanks for all the responses.  I am going through each one and then will let you know what works best.</description>
      <pubDate>Tue, 30 Dec 2003 14:34:03 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/addition-in-shell-script/m-p/3153907#M884806</guid>
      <dc:creator>Ryan B</dc:creator>
      <dc:date>2003-12-30T14:34:03Z</dc:date>
    </item>
    <item>
      <title>Re: Addition in Shell Script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/addition-in-shell-script/m-p/3153908#M884808</link>
      <description>count=555.07&lt;BR /&gt;&lt;BR /&gt;Inside the loop put the following line:&lt;BR /&gt;&lt;BR /&gt;count=`awk -v x=$count -v y=0.01 'BEGIN{  printf "%.2f\n", x+y}'`&lt;BR /&gt;&lt;BR /&gt;Elena.</description>
      <pubDate>Tue, 30 Dec 2003 14:38:24 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/addition-in-shell-script/m-p/3153908#M884808</guid>
      <dc:creator>Elena Leontieva</dc:creator>
      <dc:date>2003-12-30T14:38:24Z</dc:date>
    </item>
    <item>
      <title>Re: Addition in Shell Script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/addition-in-shell-script/m-p/3153909#M884810</link>
      <description>The bc and awk methods, last 2 posts, worked the best for my situation. However, I appreciate the rest of the responses as I learned other methods for the future.  Thanks again and have great New Year!!&lt;BR /&gt;&lt;BR /&gt;Ryan</description>
      <pubDate>Tue, 30 Dec 2003 15:07:23 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/addition-in-shell-script/m-p/3153909#M884810</guid>
      <dc:creator>Ryan B</dc:creator>
      <dc:date>2003-12-30T15:07:23Z</dc:date>
    </item>
    <item>
      <title>Re: Addition in Shell Script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/addition-in-shell-script/m-p/3153910#M884811</link>
      <description>Elena,&lt;BR /&gt;&lt;BR /&gt;Regarding the awk command, what does the ""%.2f\n" in printf mean?&lt;BR /&gt;&lt;BR /&gt;Ryan</description>
      <pubDate>Tue, 30 Dec 2003 15:17:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/addition-in-shell-script/m-p/3153910#M884811</guid>
      <dc:creator>Ryan B</dc:creator>
      <dc:date>2003-12-30T15:17:15Z</dc:date>
    </item>
    <item>
      <title>Re: Addition in Shell Script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/addition-in-shell-script/m-p/3153911#M884812</link>
      <description>Ryan,&lt;BR /&gt;&lt;BR /&gt;It means that the printf function prints the result with a precision of two places to the right of the decimal point. &lt;BR /&gt;&lt;BR /&gt;Elena.&lt;BR /&gt;</description>
      <pubDate>Tue, 30 Dec 2003 15:27:24 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/addition-in-shell-script/m-p/3153911#M884812</guid>
      <dc:creator>Elena Leontieva</dc:creator>
      <dc:date>2003-12-30T15:27:24Z</dc:date>
    </item>
    <item>
      <title>Re: Addition in Shell Script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/addition-in-shell-script/m-p/3153912#M884813</link>
      <description>I like Elena's awk solution also.  See "man printf" under the Conversion Specifications section for detailed info about the different types of formatting you can do in "printf" under awk.</description>
      <pubDate>Fri, 02 Jan 2004 07:01:04 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/addition-in-shell-script/m-p/3153912#M884813</guid>
      <dc:creator>Alex Ostapenko</dc:creator>
      <dc:date>2004-01-02T07:01:04Z</dc:date>
    </item>
    <item>
      <title>Re: Addition in Shell Script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/addition-in-shell-script/m-p/3153913#M884814</link>
      <description>I'd like to do the opposite, change 555.07 to 556.07. I can get the first 3 integers&lt;BR /&gt; to change, but the last 2 will not show.&lt;BR /&gt;&lt;BR /&gt; Thanks for any pointers...&lt;BR /&gt;&lt;BR /&gt; Rich</description>
      <pubDate>Mon, 10 May 2004 14:20:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/addition-in-shell-script/m-p/3153913#M884814</guid>
      <dc:creator>Rich Polk</dc:creator>
      <dc:date>2004-05-10T14:20:15Z</dc:date>
    </item>
  </channel>
</rss>

