- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: integer math in ksh
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
тАО08-07-2007 01:44 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-07-2007 01:49 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-07-2007 01:53 AM
тАО08-07-2007 01:53 AM
Re: integer math in ksh
...I should add that if you are doing arithmetic in a shell, 'typeset'ing your variables to integers speeds things up a bit, too:
#!/usr/bin/ksh
typeset -i X=2
typeset -i Y=8
typeset -i Z
Z=$((X*Y))
echo ${Z}
Regards!
...JRF...
- Tags:
- typeset
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-07-2007 02:01 AM
тАО08-07-2007 02:01 AM
Re: integer math in ksh
The following works on the command line, but doesn't work in the shell script. The exact line that blows up is the multiplication line.
#!/bin/ksh
# find total space available in each VG
for VG in `strings /etc/lvmtab |grep -v dsk`
do
echo processing $VG
TOTAL_PE=`vgdisplay -v $VG | grep ^"Total PE" | awk '{print $3}'`
PE_SIZE=`vgdisplay -v $VG | grep ^"PE Size (Mbytes)" | awk '{print $4}'`
echo TOTAL_PE_=$TOTAL_PE
echo PE_SIZE=$PE_SIZE
((TOTAL_SIZE=$TOTAL_PE * $PE_SIZE)) # does not work in ksh
# ((TOTAL_SIZE=$TOTAL_PE * $PE_SIZE)) # works in dtksh
echo TOTAL_SIZE=$TOTAL_SIZE
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-07-2007 02:05 AM
тАО08-07-2007 02:05 AM
Re: integer math in ksh
change this:
((TOTAL_SIZE=$TOTAL_PE * $PE_SIZE))
to this:
TOTAL_SIZE=$(( ${TOTAL_PE} * ${PE_SIZE} ))
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-07-2007 02:13 AM
тАО08-07-2007 02:13 AM
Re: integer math in ksh
Exactly what error do you see? This works for me. You could try running with a trace:
# ksh -x my.sh 2>&1|more
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-07-2007 02:30 AM
тАО08-07-2007 02:30 AM
Re: integer math in ksh
this worked beautifully, thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-07-2007 02:36 AM
тАО08-07-2007 02:36 AM
Re: integer math in ksh
that one works well also:
total_size=$((total_pe*pe_size))