Welcome to the most active Linux Forum on the web.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 05-10-2006, 03:11 PM   #1
Senior Member
Registered: Feb 2004
Location: lost+found
Distribution: CentOS
Posts: 1,339

Rep: Reputation: 55
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, 03:14 PM   #2
Senior Member
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,124

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


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 01:21 PM
Shell script --cannot assign variable-- ralvez Programming 6 02-24-2006 05:56 PM
problem with sed n variable in shell script dipenchaudhary Programming 4 02-12-2006 11:54 PM
expanding variable in shell script dipenchaudhary Programming 8 02-08-2006 06:05 PM
Odd problem with making a variable the output of a command in a shell script linux=future Programming 3 12-13-2005 10:45 PM

All times are GMT -5. The time now is 09:12 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