LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 05-10-2006, 02:11 PM   #1
abefroman
Senior Member
 
Registered: Feb 2004
Location: Chicago
Distribution: CentOS
Posts: 1,263

Rep: Reputation: 53
Problem with shell script using a variable from a unix command.


It is not putting the number only in $swap.

How can I get it to store the 4th number only from free -m |grep Swap?

$swap=`free -m |grep Swap | awk {'print $4'}`;
if($swap < 100){
print "swap low";
}

Thanks in advance!
 
Old 05-10-2006, 02:14 PM   #2
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,123

Rep: Reputation: 162Reputation: 162
Don't put the '$' in front of the variable name when you're assigning to it. For example, the following works on my PC:
Code:
SWAP=`free -m | grep Swap | awk {'print $4'}`
echo $SWAP
 
  


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
Problem executing mv command inside shell script pablogosse Linux - General 7 12-16-2009 12:21 PM
Shell script --cannot assign variable-- ralvez Programming 6 02-24-2006 04:56 PM
problem with sed n variable in shell script dipenchaudhary Programming 4 02-12-2006 10:54 PM
expanding variable in shell script dipenchaudhary Programming 8 02-08-2006 05:05 PM
Odd problem with making a variable the output of a command in a shell script linux=future Programming 3 12-13-2005 09:45 PM


All times are GMT -5. The time now is 07:30 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration