Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Mailing Lists -> Oracle-L -> Re: OT:korn shell and arithmetic

Re: OT:korn shell and arithmetic

From: Shawn Ferris <shawn_at_virtualsmf.net>
Date: Thu, 24 Jun 2004 12:37:32 -0600 (MDT)
Message-ID: <5734.168.215.22.23.1088102252.squirrel@mail.virtualsmf.net>


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_at_freelists.org put 'unsubscribe' in the subject line.
--
Archives are at http://www.freelists.org/archives/oracle-l/
FAQ is at http://www.freelists.org/help/fom-serve/cache/1.html
-----------------------------------------------------------------
Received on Thu Jun 24 2004 - 13:25:02 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US