HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Shell script problem
Operating System - HP-UX
1833873
Members
2953
Online
110063
Solutions
Forums
Categories
Company
Local Language
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
back
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
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Topic Options
- 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
10-16-2008 08:27 AM
10-16-2008 08:27 AM
Shell script problem
Hi All
can any one tell is their any limitation in lengh of numeric value that expr function can operate ?
means ,in shell script if i have set a value Y=100000000000( more than 10 digit) and Z =100000000000 ( more than 10 digit).
and do "expr $Y + $Z" i should get 200000000000, but i am getting some negative value . If i use 9 digit numbers for Y and Z i will get correct output .
Please tell me why it is happeing and how to over come the same
Bibith Dathan
can any one tell is their any limitation in lengh of numeric value that expr function can operate ?
means ,in shell script if i have set a value Y=100000000000( more than 10 digit) and Z =100000000000 ( more than 10 digit).
and do "expr $Y + $Z" i should get 200000000000, but i am getting some negative value . If i use 9 digit numbers for Y and Z i will get correct output .
Please tell me why it is happeing and how to over come the same
Bibith Dathan
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2008 08:35 AM
10-16-2008 08:35 AM
Re: Shell script problem
Hi:
The shell is using 32-bit arithmetic and you are seeing an overflow. See our discussion here:
http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1273761
Regards!
...JRF...
The shell is using 32-bit arithmetic and you are seeing an overflow. See our discussion here:
http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1273761
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2008 12:30 AM
10-17-2008 12:30 AM
Re: Shell script problem
Hi Bibith,
If you want to use large numbers you need to use bc as coprocess.
i.e.:
a=$(echo "$Z+$Y" |bc)
or ksh coprecess
bc |& # start bc as coprocess
exec 3>&p 4<&p
echo "$Z+$Y" >&3
read result <&4
echo $result
echo ".+$Z" >&3
read result <&4
echo $result
echo ".*$Z" >&3
read result <&4
echo $result
exec 3<&- 4<&- # to exit the coprocess
bc is using unlimited arithmetic.
if yu want floating points or mathematical functions use "bc -l"
If you want to use large numbers you need to use bc as coprocess.
i.e.:
a=$(echo "$Z+$Y" |bc)
or ksh coprecess
bc |& # start bc as coprocess
exec 3>&p 4<&p
echo "$Z+$Y" >&3
read result <&4
echo $result
echo ".+$Z" >&3
read result <&4
echo $result
echo ".*$Z" >&3
read result <&4
echo $result
exec 3<&- 4<&- # to exit the coprocess
bc is using unlimited arithmetic.
if yu want floating points or mathematical functions use "bc -l"
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP