Question about envvar in shell script

  • Follow


Hello,

I have the following example script snipplet which demonstrates my misery:

################# starts ###########################
function fff {
        sleep 1
        Z=hello
}

fff
echo $Z
################# ends ###########################

And I get hello.

However, if I run like this, then I don't get anything:

################# starts ###########################
function fff {
        sleep 1
        Z=hello
}

fff &
wait
echo $Z
################# ends ###########################

Z is empty.

Anybody knows how to get around this? I would have two processes,
each taking about 1-2 minutes, and they can be run parallel. And
each processes need to be replayed hundreds of times, so if I can
parallelize them, it would be a great time saver.

Actually, I would like the result of fff to go into envvars
something like this:

T1=`fff hello` &
T2=`fff world` &

And I get nothing.

Thanks, Vilmos
0
Reply vilmos2 (252) 12/21/2007 5:40:54 PM

On 2007-12-21, Vilmos Soti <vilmos@soti.ca> wrote:
>
>
> Hello,
>
> I have the following example script snipplet which demonstrates my misery:
>
> ################# starts ###########################
> function fff {
>         sleep 1
>         Z=hello
> }
>
> fff
> echo $Z
> ################# ends ###########################
>
> And I get hello.
>
> However, if I run like this, then I don't get anything:
>
> ################# starts ###########################
> function fff {
>         sleep 1
>         Z=hello
> }
>
> fff &
> wait
> echo $Z
> ################# ends ###########################
>
> Z is empty.
>
> Anybody knows how to get around this? I would have two processes,
> each taking about 1-2 minutes, and they can be run parallel. And
> each processes need to be replayed hundreds of times, so if I can
> parallelize them, it would be a great time saver.
>
> Actually, I would like the result of fff to go into envvars
> something like this:
>
> T1=`fff hello` &
> T2=`fff world` &
>
> And I get nothing.
>
> Thanks, Vilmos

When you do anything in the background, it's in a separate shell.
You might write a function that sets a variable and then starts a 
background process, for example:
fff () {
Z=1
sleep 1 &
}
0
Reply marcumbill (1012) 12/21/2007 7:08:29 PM


Bill Marcum <marcumbill@bellsouth.net> writes:

> When you do anything in the background, it's in a separate shell.
> You might write a function that sets a variable and then starts a 
> background process, for example:
> fff () {
> Z=1
> sleep 1 &
> }

Thanks for the info. Finally I resolved in a bit different (and less
elegant) way:

fff > out &

Vilmos
0
Reply vilmos2 (252) 12/21/2007 7:26:44 PM

2 Replies
30 Views

(page loaded in 0.28 seconds)

Similiar Articles:













7/28/2012 11:15:56 AM


Reply: