- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: how can add two variables?
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
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
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-22-2002 03:22 PM
08-22-2002 03:22 PM
how can add two variables?
in the next scrip i have the next script:
-----------------------------------------
#Progrma que calcula el total de memoria #utilizada
ps aux |cut -b 34-37 |grep K | awk '{s=s+$1}\{r=s/1024}END{print r,export $r}'
ps aux | cut -b 34-37 | grep M | awk '{t=t+$1}\END{print t}'
-----------------------------------------
but i need sum both and print the result
how can doing it?
thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2002 03:39 PM
08-22-2002 03:39 PM
Re: how can add two variables?
TIMEOUT
export $r ???
Might work in LINUX but not in any UNIX that I know of, UNLESS you plan on installing GNU's AWK!
Now, how to do it:
ps aux | cut -b 34-37 | grep -e K -e M |
awk '{lenofvar=length($1);
if (substr($1,lenofvar,1) eq "K") {s=s+$1;r=s/1024}
if (substr($1,lenofvar,1) eq "M") {t=t+$1}
}
END{printf "%d/n",r;
print t}'
Can't test it, but looks good???
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2002 05:07 PM
08-22-2002 05:07 PM
Re: how can add two variables?
I'd like you to take a look at this thread. It helps you and everyone else in the future:
http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x022718276953d61190040090279cd0f9,00.html
And I'd like to add that you need to be more interactive with your thread so that people know what works and what doesn't.
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2002 01:59 AM
08-23-2002 01:59 AM
Re: how can add two variables?
Assign:
variable=`command`
or
variable=$(command)
Add:
((result=$var1+$var2))
Print:
echo $result
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2002 11:56 AM
08-23-2002 11:56 AM
Re: how can add two variables?
((result = var1 + var2))
or
let result=var1+var2
are also both acceptable.
-Allan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2002 12:03 PM
08-23-2002 12:03 PM
Re: how can add two variables?
Nicely, put! You are getting more diplomatic in your old age? Or are you getting tired of the flaming tirades?
:-)
Marty