Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Mailing Lists -> Oracle-L -> Re: OT:korn shell and arithmetic
On 06/22/2004 11:27:12 PM, Tim Gorman wrote:
> Sorry, my friend, but that doesn't work...
>
> $ if [ 1.2 > 1.0 ]; then
> > echo "yes"
> > else echo "no"
> > fi
> yes
>
> $ if [ 1.2 > 1.3 ]; then
> > echo "yes"
> > else echo "no"
> > fi
> yes
>
> The following is rather annoying, but it seems to work...
>
> $ if [[ "`bc << __EOF__^J1.2 > 1.0^J__EOF__`" = "1" ]]
> > then
> > echo yes
> > else echo no
> > fi
> yes
>
> $ if [[ "`bc << __EOF__^J1.2 > 1.3^J__EOF__`" = "1" ]]
> > then
> > echo yes
> > else echo no
> > fi
> no
>
Hey Tim, long time no see! It seems that "-gt" is the correct comparison operator for the numerical values. Other then that, pdksh has only integer arithmetic implemented. Here is a revised version, without those pesky decimal points:
$ cat /tmp/ttt;/tmp/ttt
#!/bin/ksh
if [ 2 -gt 3 ]; then
echo "yes";
else echo "no";
fi;
if [ 3 -gt 2 ]; then
echo "yes";
else echo "no";
fi;
no
yes
$
My preferred shell (all right, it's an interpreter, not a shell) for that kind of tricks is perl.
It looks much nicer:
$ cat /tmp/ttt;/tmp/ttt
#!/usr/bin/perl
if (1.2 > 1.3) { print "yes\n"; } else { print "no\n"; } if (1.3 > 1.2) { print "yes\n"; } else { print "no\n"; }
print "The sum is:", 1.2+1.3,"\n";
no
yes
The sum is:2.5
$
-- Mladen Gogala Oracle DBA ---------------------------------------------------------------- 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 Wed Jun 23 2004 - 00:40:02 CDT
![]() |
![]() |