Solved

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

Posted on 2004-08-13
6
260 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
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 …

864 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

21 Experts available now in Live!

Get 1:1 Help Now