Share your knowledge at the LQ Wiki.
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, 08: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, 10:06 PM   #2
Senior Member
Registered: May 2015
Distribution: Slackware, OpenBSD
Posts: 1,464

Rep: Reputation: 828Reputation: 828Reputation: 828Reputation: 828Reputation: 828Reputation: 828Reputation: 828
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 12:32 PM.
Old 07-11-2015, 08:24 AM   #3
Senior Member
Registered: Sep 2011
Location: Upper Hale, Surrey/Hants Border, UK
Posts: 4,018

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 05:43 PM
assign number to interface Ammad Linux - Hardware 1 01-05-2015 09:21 AM
[SOLVED] assign full name to variable then grep a file for the variable socalheel Programming 3 09-16-2013 12:04 PM
[SOLVED] BASH: Assign a variable to a variable name... c_henry Programming 9 06-04-2012 12:33 PM
How do you assign a variable to be a variable file name in a directory? David_Elliott Programming 4 04-14-2009 11:19 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:23 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
Open Source Consulting | Domain Registration