How the subshell communicate with parent shell?

How the subshell communicate with parent shell?

Post by Sharon Xiaoyun Kon » Sat, 10 Feb 2001 06:11:04



In the korn shell, one can "export" some enviroment variable to let its
subshell inherited. But how can subshell
communicate with its parent shell? In another word, how can subshell let
its parent know the value of variable
which defined inside this subshell?

Thanks,

--
Sharon Xiaoyun Kong
------------------------------------

Tel: 914-892-4489
IBM internal number: 532-4489

 
 
 

How the subshell communicate with parent shell?

Post by Kurt J. Lanz » Sat, 10 Feb 2001 06:34:31



> In the korn shell, one can "export" some enviroment variable to let its
> subshell inherited. But how can subshell
> communicate with its parent shell? In another word, how can subshell let
> its parent know the value of variable
> which defined inside this subshell?

> Thanks,

It can't. No child process can change the environment of
its parent. Period. That's how unix works. The best a
parent can do is accept/process the standard output from
one of its children, as in a pipeline (to a file) or via
"command substitution", ie "backticks" or $(). But no
parent, shell or not, has access to the child's
environment after the child has been invoked.

 
 
 

How the subshell communicate with parent shell?

Post by laura fairhe » Sat, 10 Feb 2001 10:15:21



Quote:> In the korn shell, one can "export" some enviroment variable to let its
> subshell inherited. But how can subshell
> communicate with its parent shell? In another word, how can subshell let
> its parent know the value of variable
> which defined inside this subshell?

> Thanks,

You can't set the variables of the parent shell directly,
but there are many ways to do it indirectly. The usual technique
is to use stdout. The parent can then set a single variable
by using command subsitution (grave quotes, or POSIX '$(')
or you could even set more than one variable using the eval
command. You can also use the return value $? but that doesn't
give much flexibility.

Bye,

L

> --
> Sharon Xiaoyun Kong
> ------------------------------------

> Tel: 914-892-4489
> IBM internal number: 532-4489

 
 
 

How the subshell communicate with parent shell?

Post by Dan Merc » Sat, 10 Feb 2001 22:56:39




> In the korn shell, one can "export" some enviroment variable to let its
> subshell inherited. But how can subshell
> communicate with its parent shell? In another word, how can subshell let
> its parent know the value of variable
> which defined inside this subshell?

> Thanks,

> --
> Sharon Xiaoyun Kong
> ------------------------------------

> Tel: 914-892-4489
> IBM internal number: 532-4489

What are you really trying to do?  It's possible what you are
attempting can be done with functions or by sourcing scripts.

--
Dan Mercer

Opinions expressed herein are my own and may not represent those of my employer.

 
 
 

How the subshell communicate with parent shell?

Post by Olaf Buckman » Sun, 11 Feb 2001 00:26:25


Hi there


> In the korn shell, one can "export" some enviroment variable to let its
> subshell inherited. But how can subshell
> communicate with its parent shell? In another word, how can subshell let
> its parent know the value of variable
> which defined inside this subshell?

> Thanks,

> --
> Sharon Xiaoyun Kong
> ------------------------------------

> Tel: 914-892-4489
> IBM internal number: 532-4489

Maybe use a little trick.

What evere result you get on a variable, write it to a file ind /tmp (e.g.
like /tmp/myvar.txt).
Later on read this file in the parent shell and assign variable (or the
lines of variables) back to variables in the parentshell.

And don't forget to delete afterwards the tmp file.

It is maybe not a good solution, but it should work.

Cheers

Olaf