From: Charles Sharp (charles.sharp at domain ireland.sun.com)
Date: Wed 30 May 2001 - 11:20:09 IST
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
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?
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 at domain 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 domain linux.ie
> http://www.linux.ie/mailman/listinfo/ilug for (un)subscription information.
> List maintainer: listmaster at domain linux.ie
This archive was generated by hypermail 2.1.6 : Thu 06 Feb 2003 - 13:10:30 GMT