Solved

How to make a variable in a shell script program equal to the output from a command.

Posted on 2004-08-13
6
273 Views
Last Modified: 2010-05-18
Hi,

I have a command like

grep "good work" myfile.results | wc -l

in my bash shell script.

I normally output this to a file, but I would prefer to be able to put this into a variable I can keep (and then modify).

Any idea how to do this?

i tried
hello=grep "good work" myfile.results | wc -l

but that didn't work :(

Thanks.

-Edward
0
Comment
Question by:edwardt
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 6

Accepted Solution

by:
ren_b earned 250 total points
ID: 11797611
hello=`grep "good work" myfile.results | wc -l`
0
 

Author Comment

by:edwardt
ID: 11797671
Hi,
On my file, I need to reference some vairalbles too, but it seems

hello='grep "good work" "$1${i}.results" | wc -l'

doesn't work.

Thanks.

-Edward
0
 
LVL 6

Expert Comment

by:ren_b
ID: 11797692
don't use the ' (single quote), you have to use the ` (backtick).
0
Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

 

Author Comment

by:edwardt
ID: 11797703
also, when I try to do
hello=`grep "good work" myfile.results | wc -l`
and i do echo "hello is ${hello}" i get the string.

Thanks.

Edward
0
 

Author Comment

by:edwardt
ID: 11797728
Ah, thanks! :)

-Edward
0
 
LVL 6

Expert Comment

by:ren_b
ID: 11797739
> also, when I try to do
> hello=`grep "good work" myfile.results | wc -l`
> and i do echo "hello is ${hello}" i get the string.

that's what you want isn't it?
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Simple Linear Regression
Starting up a Project

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question