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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
11-17-2008, 06:48 AM
|
#1
|
LQ Newbie
Registered: Nov 2008
Posts: 3
Rep:
|
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.
|
|
|
11-17-2008, 06:57 AM
|
#2
|
LQ Guru
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509
|
Quote:
Originally Posted by dimako83
[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.
|
|
|
11-17-2008, 07:07 AM
|
#3
|
LQ Newbie
Registered: Nov 2008
Posts: 3
Original Poster
Rep:
|
but then I get this error:
bash: var1temp: command not found
|
|
|
11-17-2008, 07:09 AM
|
#4
|
LQ Guru
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509
|
Quote:
Originally Posted by dimako83
but then I get this error:
bash: var1temp: command not found
|
Either don't put blank spaces around the = sign.
|
|
|
11-17-2008, 07:13 AM
|
#5
|
LQ Veteran
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,316
|
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 07:14 AM.
|
|
|
11-17-2008, 07:23 AM
|
#6
|
LQ Newbie
Registered: Nov 2008
Posts: 3
Original Poster
Rep:
|
It works now! Thank you!
I knew it was something stupid.... sorry for bothering you with such a stupid issue, well thank you again!
|
|
|
11-17-2008, 08:22 AM
|
#7
|
LQ Guru
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509
|
Quote:
Originally Posted by dimako83
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!
|
|
|
All times are GMT -5. The time now is 06:02 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|