- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- script question
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-17-2004 10:01 AM
тАО05-17-2004 10:01 AM
I am trying to compare 2 numerical values using test command (i.e -ge, -gt).
However when comparing 2 big values the test command return incorrect result. Below example return KS0 greater than KS1. The result should be the other way around. Thanks.
Example:
KS0=524288000
KS1=4294967295
if [ $KS0 -gt $KS1 ]; then
echo "$KS0"
fi
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-17-2004 10:17 AM
тАО05-17-2004 10:17 AM
Re: script question
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-17-2004 10:33 AM
тАО05-17-2004 10:33 AM
Solution#!/usr/bin/sh
compare()
{
typeset -i10 RSLT=0
typeset A=${1}
typeset B=${2}
shift 2
RSLT=$(echo "a=${A}; b=${B}; r=0; if (a < b) r=(-1)l if (a > b) r=1; r" | bc)
echo "${RSLT}"
return 0
} # compare
typeset -i10 CMP=$(compare ${KS0} ${KS1})
if [[ ${CMP} -ge 0 ]]
then
echo "KS0 GE KS1"
else
echo "KS0 LT KS1"
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-18-2004 02:21 AM
тАО05-18-2004 02:21 AM
Re: script question
typeset -RZ10 KS0X=$KS0
typeset -RZ10 KS1X=$KS1
if [ $KS0X > $KS1X ] ; then
echo "$KS0"
fi
By using typeset to right-justify zero fill the value, then a string compare will work.
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-18-2004 03:04 AM
тАО05-18-2004 03:04 AM
Re: script question
compare()
{
typeset -i10 RSLT=0
typeset A=${1}
typeset B=${2}
shift 2
RSLT=$(echo "scale=8; a=(${A}); b=(${B}); r=0; if (a < b) r=(-1); if (a > b) r=1; r" | bc)
echo "${RSLT}"
return 0
} # compare
That should now compare any combination of numerical values including floating point values (up to 8 decimal places set by scale=8) as well as integers.