Re: OT:korn shell and arithmetic

  • From: "Shawn Ferris" <shawn@xxxxxxxxxxxxxx>
  • To: oracle-l@xxxxxxxxxxxxx
  • Date: Thu, 24 Jun 2004 12:37:32 -0600 (MDT)

So, I'm a little behind on the list.. but:

> Sorry, my friend, but that doesn't work...
>
>     $ if [ 1.2 > 1.0 ]; then

doesn't work because it's using an alpha comparison.. not numeric. Use
'-gt' instead (done in the original email) And as someone mentioned, test
only works on whole numbers.

> The following is rather annoying, but it seems to work...
>
>     $ if [[ "`bc << __EOF__^J1.2 > 1.0^J__EOF__`" = "1" ]]

This would be less annoying:

if [[ "`echo "1.2 > 1.0" | bc `" = "1" ]]

However, I like annoying.. colleagues can't read my code anyway.. so that
fits right in! 8D However, I couldn't get bc on solaris to support that..
so:

$ if [ "`expr 1.2 \> 1.0`" = "1" ]

In fact, I think expr will return a result status accordingly, so:

$ if expr 1.2 \> 1.0 >/dev/null; then
$   echo yes
$ else
$   echo no
$ fi

I think this will work anywhere. (tried on Solaris, Hpux and linux)

HTH

Shawn -- 8D
Sr. Database Administrator
----------------------------------------------------------------
Please see the official ORACLE-L FAQ: http://www.orafaq.com
----------------------------------------------------------------
To unsubscribe send email to:  oracle-l-request@xxxxxxxxxxxxx
put 'unsubscribe' in the subject line.
--
Archives are at //www.freelists.org/archives/oracle-l/
FAQ is at //www.freelists.org/help/fom-serve/cache/1.html
-----------------------------------------------------------------

Other related posts: