Re: [ILUG] Bash Function

From: kevin lyda (kevin at domain suberic.net)
Date: Wed 30 May 2001 - 10:10:57 IST


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 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"


This archive was generated by hypermail 2.1.6 : Thu 06 Feb 2003 - 13:10:30 GMT