LINUX.IE, website of the Irish Linux Users' Group
Tux rules!

   
Home
New Users
Articles
Download
Projects
Community
Vendors

  Print Version
 
Archives:


planetILUG

Recent News

News Archive


Join the
ILUG
on FaceBook


Join the
ILUG
on LinkedIn


Join the
ILUG SETI
Group



















 
 :: Mailing Lists

[ILUG] Bash Function

[ILUG] Bash Function

Charles Sharp charles.sharp at ireland.sun.com
Wed May 30 11:20:09 IST 2001


Hi Ross,

Interesting situation, but I'm somewhat confused.

You say you want to "quietly" start a background
process.  But then you say you want the output
of the process put into a variable.

Are you trying to do a co-process? Or do you have
an independent process that you want to check the
final status/output of?  What's the point of putting
it in the background if your script needs something
from it?

If you do put something in the background, you need
to be concerned about when the process stops.
Otherwise, the variable has no real meaning to you.
For example, Kevin's solution will work only if 
cmd2 runs _really_ quickly, like instantaneously.

Maybe a little more information about what you're
trying to accomplish would help?

rgds,
cas


kevin lyda wrote:
> 
> On Wed, May 30, 2001 at 06:50:38AM +0100, Ross Davis wrote:
> > That works the finest 'cept I'm trying to put cmd2's
> > output into a variable, something like:
> 
> well you're just a pita, aren't you!  :)
> 
> > cmd1 && ((var=$(cmd2))&)
> >
> > or equiv.,
> >
> > cmd1 && ((var=`cmd2`)&)
> >
> > No combination of brackets seem to work. Anybody
> > got any idea if something like this is possible
> > or another solution!?
> 
> and no combination will work as far as i can see because the ()'s create
> a subshell.  what this means is that the shell creates a child process
> and runs the command in there - and environment variables go down to
> children but never up to parents.
> 
> so, your best bet is:
> 
> cmd1 && (cmd2 > cmd2.out &); var=$(cat cmd2.out); rm cmd2.out
> 
> kevin
> 
> --
> kevin at suberic.net          "Maybe one day downtrodden poo-eaters will
> fork()'ed on 37058400       get a fair shake in Savage Love, but it's
> meatspace place: home       not going to be today."
> http://suberic.net/~kevin                 --dan savage, "savage love"
> 
> --
> Irish Linux Users' Group: ilug at linux.ie
> http://www.linux.ie/mailman/listinfo/ilug for (un)subscription information.
> List maintainer: listmaster at linux.ie




More information about the ILUG mailing list
Read this without the formatting.
                                                                                                    

 

Hosted by HEAnet


Maintained by the ILUG website team. The aim of Linux.ie is to support and help commercial and private users of Linux in Ireland. You can display ILUG news in your own webpages, read backend information to find out how. Networking services kindly provided by HEAnet, server kindly donated by Dell. Linux is a trademark of Linus Torvalds, used with permission. No penguins were harmed in the production or maintenance of this highly praised website. Looking for the Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!
RSS Version
Powered by Dell