LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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 07-14-2006, 07:18 AM   #1
gn00kie
Member
 
Registered: Jan 2006
Posts: 70

Rep: Reputation: 15
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..

Last edited by gn00kie; 07-14-2006 at 07:26 AM.
 
Old 07-15-2006, 03:04 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
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 ]"
 
  


Reply



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
how to save output from a command to a variable? tomolesonjr Linux - Newbie 6 04-19-2006 03:04 PM
passing command output to variable Infernal211283 Linux - Newbie 12 01-11-2006 05:54 AM
shell scipting: append output of a command to a variable jonhewer Linux - Newbie 10 08-24-2005 05:42 AM
Can we specify variable field width in a scanf() format string? skie_knite007 Programming 3 05-13-2005 12:56 PM
Assigning the output of one command to a variable (shell) guru_stew Programming 5 08-03-2003 06:12 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:21 AM.

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