Solved

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

Posted on 2004-08-13
6
264 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
  • 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
wordcount challenge 11 121
groovy example issue 10 97
autoit - check if option is checked in another program 2 127
how to update exe applicatio from internet ? 6 76
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
A short article about problems I had with the new location API and permissions in Marshmallow
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

813 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now