- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Performing simple math calculations in 'sh"
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
Forums
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
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
тАО09-26-2006 04:51 AM
тАО09-26-2006 04:51 AM
typeset -i
typeset -i
echo $
but that doesn't seem to be supported for sh.
Can anyone suggest an alternate method for performing this type of operation?
Would some form of "eval" work?
Thanks.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-26-2006 04:55 AM
тАО09-26-2006 04:55 AM
Solutiontypeset -i A=100
typeset -i B=50
typeset -i C=0
C=$((${A} - ${B}))
echo "Result = ${C}"
This syntax also works in ksh.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-26-2006 04:58 AM
тАО09-26-2006 04:58 AM
Re: Performing simple math calculations in 'sh"
One way:
# typeset -i var1=1
# typeset -i var2=3
# let var3=var1+var2
# echo ${var3}
Another way, in lieu of using 'let' is:
# var3=$(( $var1 + $var2 ))
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-26-2006 05:02 AM
тАО09-26-2006 05:02 AM
Re: Performing simple math calculations in 'sh"
$ echo $SHELL
/sbin/sh
$ var2=30
$ var3=15
$ (( var1 = var2 - var3 ))
$ echo $var1
15
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-26-2006 05:08 AM
тАО09-26-2006 05:08 AM
Re: Performing simple math calculations in 'sh"
# i=$(( 5 + 6 ))
# echo $i
11
# i=$(( 5 - 6 ))
# echo $i
-1
# typeset -i a
# typeset -i b
# a=10
# b=12
# i=$(( $a - $b ))
# echo $i
-2
Carsten
In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move. -- HhGttG
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-26-2006 05:22 AM
тАО09-26-2006 05:22 AM
Re: Performing simple math calculations in 'sh"
1. let A=$B+$C
2. A=$(($A+$B))
3. A=$(expr $B + $C)
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-29-2006 04:11 AM
тАО12-29-2006 04:11 AM
Re: Performing simple math calculations in 'sh"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-29-2006 04:12 AM
тАО12-29-2006 04:12 AM