Solved

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

Posted on 2004-08-13
6
257 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
Comment Utility
hello=`grep "good work" myfile.results | wc -l`
0
 

Author Comment

by:edwardt
Comment Utility
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
Comment Utility
don't use the ' (single quote), you have to use the ` (backtick).
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:edwardt
Comment Utility
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
Comment Utility
Ah, thanks! :)

-Edward
0
 
LVL 6

Expert Comment

by:ren_b
Comment Utility
> 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

RIA (Rich Internet Application) tools are interactive internet applications which have many of the characteristics of desktop applications. The RIA tools typically deliver output either by the way of a site-specific browser or via browser plug-in. T…
Here we come across an interesting topic of coding guidelines while designing automation test scripts. The scope of this article will not be limited to QTP but to an overall extent of using VB Scripting for automation projects. Introduction Now…
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
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 …

744 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

15 Experts available now in Live!

Get 1:1 Help Now