LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   how to format the output of a command and save it into a string variable (http://www.linuxquestions.org/questions/programming-9/how-to-format-the-output-of-a-command-and-save-it-into-a-string-variable-463962/)

gn00kie 07-14-2006 07:18 AM

how to format the output of a command and save it into a string variable
 
Hi guys,
I have a script that would return the cpu load of a machine. I want to get the numerical part of the output, but I do not know how to do it.


<code snippet>
result="$(snmpget -v 2c -c public localhost -Ov .1.3.6.1.4.1.2021.11.11.0)"
if [${result##INTEGER: }=95]; then
echo $result
fi
</code snippet>

When I execute the command, I get "./montop.sh: line 13: [95=95]: command not found" error. How do I solve this problem? TIA.

edited:
I got the wrong part already. It was in my if statement.. :)

acid_kewpie 07-15-2006 03:04 AM

well for clarity the [ is actually a command alias for test. just like you can't run "cd/my/directory" you can't run "[1=0]" due to whitespace issues, it.d be "[ 1 = 0 ]"


All times are GMT -5. The time now is 11:43 PM.