Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 07-10-2015, 07:44 PM   #1
LQ Newbie
Registered: Jul 2015
Posts: 1

Rep: Reputation: Disabled
Assign a number to variable

I am working on getting the memory of my box and assigning it to a variable

I need commands to use both in linux and solaris box.

the problem i am facing is ,when try to assign the out of below , i am not able to do it

-bash-3.2$ sar -r 5 1

SunOS hostname 5.10 Generic_150400-16 sun4v 07/11/2015

00:42:17 freemem freeswap
00:42:22 373643 47222800

now i need to store the value 373643 (first value of the output) to a variable.....

Please suggest some ideas
Old 07-10-2015, 09:06 PM   #2
Registered: May 2015
Posts: 877

Rep: Reputation: 288Reputation: 288Reputation: 288
Assign a number to variable

Please refer to the following link for a very basic explanation of bash variables.

It's a relatively short document, and I recommend reading the whole thing. I also recommend reading the Advanced Bash Scripting guide, here:

Last edited by mralk3; 07-11-2015 at 11:32 AM.
Old 07-11-2015, 07:24 AM   #3
Senior Member
Registered: Sep 2011
Location: Upper Hale, Surrey/Hants Border, UK
Distribution: AntiX & Vuu-Do.
Posts: 1,851

Rep: Reputation: Disabled
You might also like to look at cut &/or awk.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Bash script: How to assign variable to an sqlite3 command with variable embedded? ninja6o4 Linux - Software 10 02-15-2015 04:43 PM
assign number to interface Ammad Linux - Hardware 1 01-05-2015 08:21 AM
[SOLVED] assign full name to variable then grep a file for the variable socalheel Programming 3 09-16-2013 11:04 AM
[SOLVED] BASH: Assign a variable to a variable name... c_henry Programming 9 06-04-2012 11:33 AM
How do you assign a variable to be a variable file name in a directory? David_Elliott Programming 4 04-14-2009 10:19 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:28 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration