Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Mailing Lists -> Oracle-L -> Re: OT:korn shell and arithmetic
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
-- 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
![]() |
![]() |