LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


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

Rep: Reputation: Disabled
Assign a number to variable


Hi,
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
mralk3
Slackware Contributor
 
Registered: May 2015
Distribution: Slackware
Posts: 1,900

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

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

http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-5.html

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

http://www.tldp.org/LDP/abs/html/

Last edited by mralk3; 07-11-2015 at 11:32 AM.
 
Old 07-11-2015, 07:24 AM   #3
fatmac
LQ Guru
 
Registered: Sep 2011
Location: Upper Hale, Surrey/Hants Border, UK
Distribution: Mainly Devuan with some Tiny Core, Fatdog, Haiku, & BSD thrown in.
Posts: 5,443

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


Reply


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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:25 PM.

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