LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Problem with shell script using a variable from a unix command. (https://www.linuxquestions.org/questions/programming-9/problem-with-shell-script-using-a-variable-from-a-unix-command-443545/)

abefroman 05-10-2006 02:11 PM

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!

gilead 05-10-2006 02:14 PM

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



All times are GMT -5. The time now is 12:54 PM.