LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 11-17-2008, 05:48 AM   #1
dimako83
LQ Newbie
 
Registered: Nov 2008
Posts: 3

Rep: Reputation: 0
Redirecting grep output to a variable


Hi,

I am trying to redirect grep count ("grep -wc") output to a variable but I cant succeed:

the command Im running is:

[root@***]# set var1temp
[root@***]# $var1temp = `cat 2008_11_15_1226700018.log | grep "clean" -wc`

and I receive the next error:
bash: =: command not found


Could you please help me to understand what is wrong with the command?



Thank You.
 
Old 11-17-2008, 05:57 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Quote:
Originally Posted by dimako83 View Post
[root@***]# $var1temp = `cat 2008_11_15_1226700018.log | grep "clean" -wc`
To assign a variable the correct syntax is
Code:
variable_name=something
that is: don't put the $ sign in front of the variable name. You use $variable_name when you have to retrieve the actual value of the variable.
 
Old 11-17-2008, 06:07 AM   #3
dimako83
LQ Newbie
 
Registered: Nov 2008
Posts: 3

Original Poster
Rep: Reputation: 0
but then I get this error:
bash: var1temp: command not found
 
Old 11-17-2008, 06:09 AM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Quote:
Originally Posted by dimako83 View Post
but then I get this error:
bash: var1temp: command not found
Either don't put blank spaces around the = sign.
 
Old 11-17-2008, 06:13 AM   #5
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,125

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
Not if you do it properly - seems you have a liking for imbedded spaces.

<Edit:> too slow ...

Last edited by syg00; 11-17-2008 at 06:14 AM.
 
Old 11-17-2008, 06:23 AM   #6
dimako83
LQ Newbie
 
Registered: Nov 2008
Posts: 3

Original Poster
Rep: Reputation: 0
It works now! Thank you!

I knew it was something stupid.... sorry for bothering you with such a stupid issue, well thank you again!
 
Old 11-17-2008, 07:22 AM   #7
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Quote:
Originally Posted by dimako83 View Post
It works now! Thank you!

I knew it was something stupid.... sorry for bothering you with such a stupid issue, well thank you again!
If you're new to linux or to shell programming, no question is stupid! An answer can be, anyway!
 
  


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
Trying to understand pipes - Can't pipe output from tail -f to grep then grep again lostjohnny Linux - Newbie 15 03-12-2009 10:31 PM
A little help with redirecting output tybalt Linux - Newbie 1 08-04-2007 10:08 PM
grep output on stdout and grep output to file don't match xnomad Linux - General 3 01-13-2007 04:56 AM
redirecting output using > cmk77 Slackware 8 11-10-2006 02:08 AM
Redirecting mplayer output driptray Linux - Software 1 10-12-2004 07:42 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 05:25 PM.

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