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: DONE script enclosed: shell script to compare nos.

RE: DONE script enclosed: shell script to compare nos.

From: Steve Adams <steve.adams_at_ixora.com.au>
Date: Wed, 11 Apr 2001 20:01:33 -0700
Message-ID: <F001.002E7B3B.20010411192521@fatcity.com>

Hi Raja,

I have not been following this thread until now, but the assumption that each minor point number will be two digits rather than one may not be valid. Also, if your objective is to do it entirely in the shell, consider using IFS to avoid the cut as follows.

        #!/bin/sh
        v1=$1; v2=$2
        ifs="$IFS"; IFS=.
        set $v1; v1a=$1; v1b=$2; v1c=$3
        set $v2; v2a=$1; v2b=$2; v2c=$3
        IFS="$ifs"

        if [ "0$v1a" -eq "0$v2a" ] ; then
          if [ "0$v1b" -eq "0$v2b" ] ; then
            if [ "0$v1c" -eq "0$v2c" ] ; then
               echo "$v1 is the same as $v2"
            elif [ "0$v1c" -lt "0$v2c" ] ; then
               echo "$v1 is less than $v2"
            else
               echo "$v1 is greater than $v2"
            fi
          elif [ "0$v1b" -lt "0$v2b" ] ; then
            echo "$v1 is less than $v2"
          else
            echo "$v1 is greater than $v2"
          fi
        elif [ "0$v1a" -lt "0$v2a" ] ; then
          echo "$v1 is less than $v2"
        else
          echo "$v1 is greater than $v2"
        fi

@   Regards,
@   Steve Adams

@ http://www.ixora.com.au/
@ http://www.christianity.net.au/

-----Original Message-----
Sent: Thursday, 12 April 2001 11:55
To: Multiple recipients of list ORACLE-L

 Hello every one,

Thanks for the awk script sent before, I could not use ask as some sites dont have awk but have nawk, so my script will fail. So alternatively devised this shell script, which does the job:-

#!/bin/sh

olddir="7.04.03"

olddir1="`echo $olddir| cut -c1 `"
olddir2="`echo $olddir| cut -f2 -d"." `"
olddir3="`echo $olddir| cut -f3 -d"." `"
if [ "$olddir3" = "" ]; then
  olddir3=00
fi
fullversion="$olddir1""$olddir2""$olddir3" VER="7.05"
ver1="`echo $VER| cut -c1 `"
ver2="`echo $VER| cut -f2 -d"." `"
ver3="`echo $VER| cut -f3 -d"." `"

if [ "$ver3" = "" ]; then
  ver3="00"
# echo "The third version value is $ver3" fi
fullver="$ver1""$ver2""$ver3"
if [ "$fullversion" -gt "$fullver" ];then

   echo "The $olddir version is greater than $VER version" elif [ "$fullversion" -lt "$fullver" ];then

   echo "The $olddir version is less than $VER version" else

   echo "Both versions are equal"
fi


Basically I strip away the release nos. like instead of accepting 7.04.03, I accept it as 70403 and then compare and output.

Thanks for help.

Regrads,

Raja

On Wed, 11 Apr 2001 02:30:36
 lerobe - Lee Robertson wrote:
>Why not simply do the following passing two parameters to the script eg.
>call the script test.sh and call it so
>
>test.sh 2 1
>
>This results in output "VAR1 is greater than VAR2"
>
>then
>
>test.sh 1 2
>
>this results in output "VAR2 is greater than VAR1"
>
>Cheers.
>
>#!/bin/ksh
>VAR1=$1
>VAR2=$2
>if [ "$VAR1" -gt "$VAR2" ]
>then
>echo "VAR1 is greater than VAR2"
>else
>echo "VAR2 is greater than VAR1"
>fi
>
>
>
>-----Original Message-----
>Sent: 11 April 2001 10:01
>To: Multiple recipients of list ORACLE-L
>
>
>Hi
>I'm sure there are better ways but awk does the trick
>
>echo $var1 $var2 | awk '{ if ( $1 > $2 ) { print "1"} else { print"0" } }'
>
>cheers alex
>
>> Hello,
>>
>> I need some help in comparing 2 nos. in a unix shell.
>>
>> 1) e.g var1="7.04.03"
>> and var2="7.05"
>>
>> I want to test:-
>>
>> if [ "$var2" > "$var1" ];then
>> then $var2 version is greater than $var1"
>> fi
>>
>> 2) 2nd condition is :-
>>
>> var1="7.04.03"
>> var2="7.04.02"
>>
>> I want to test:-
>> if [ "$var1" > "$var2" ];then
>> then $var1 version is greater than $var2"
>> fi
>>
>> Can some one send me a code?
>>
>> How can I do the above in shell? Can you please help me, a seemingly
>simple
>> one!
>>
>>
>> Raja
>>
>>
>>
>> Get 250 color business cards for FREE! at Lycos Mail
>> http://mail.lycos.com/freemail/vistaprint_index.html
>--
>Please see the official ORACLE-L FAQ: http://www.orafaq.com
>--
>Author: Alex Apostolopoulos
> INET: a.apostolopoulos_at_TRUCK24.com
>
>Fat City Network Services -- (858) 538-5051 FAX: (858) 538-5051
>San Diego, California -- Public Internet access / Mailing Lists
>--------------------------------------------------------------------
>To REMOVE yourself from this mailing list, send an E-Mail message
>to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in
>the message BODY, include a line containing: UNSUB ORACLE-L
>(or the name of mailing list you want to be removed from). You may
>also send the HELP command for other information (like subscribing).
>
>
>The information contained in this communication is
>confidential, is intended only for the use of the recipient
>named above, and may be legally privileged. If the reader
>of this message is not the intended recipient, you are
>hereby notified that any dissemination, distribution or
>copying of this communication is strictly prohibited.
>If you have received this communication in error, please
>re-send this communication to the sender and delete the
>original message or any copy of it from your computer
>system.
>--
>Please see the official ORACLE-L FAQ: http://www.orafaq.com
>--
>Author: lerobe - Lee Robertson
> INET: LEROBE_at_acxiom.co.uk
>
>Fat City Network Services -- (858) 538-5051 FAX: (858) 538-5051
>San Diego, California -- Public Internet access / Mailing Lists
>--------------------------------------------------------------------
>To REMOVE yourself from this mailing list, send an E-Mail message
>to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in
>the message BODY, include a line containing: UNSUB ORACLE-L
>(or the name of mailing list you want to be removed from). You may
>also send the HELP command for other information (like subscribing).
>

Get 250 color business cards for FREE! at Lycos Mail http://mail.lycos.com/freemail/vistaprint_index.html

--
Please see the official ORACLE-L FAQ: http://www.orafaq.com
--
Author: Viraj Luthra
  INET: viraj999_at_lycos.com

Fat City Network Services    -- (858) 538-5051  FAX: (858) 538-5051
San Diego, California        -- Public Internet access / Mailing Lists
--------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message
to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB ORACLE-L
(or the name of mailing list you want to be removed from).  You may
also send the HELP command for other information (like subscribing).

-- 
Please see the official ORACLE-L FAQ: http://www.orafaq.com
-- 
Author: Steve Adams
  INET: steve.adams_at_ixora.com.au

Fat City Network Services    -- (858) 538-5051  FAX: (858) 538-5051
San Diego, California        -- Public Internet access / Mailing Lists
--------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message
to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB ORACLE-L
(or the name of mailing list you want to be removed from).  You may
also send the HELP command for other information (like subscribing).
Received on Wed Apr 11 2001 - 22:01:33 CDT

Original text of this message

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