[comp.unix.questions] Subshell Variable

) (02/25/89)

Is there a way to exports system-variables from subshell, running in background
to the main shell?

I tried and tried and tried... but with no results... :-(

_____
			     ___                            ____   ___
======================= | /   |      /\     |\   |  |   |  /      /   \  |    |
Kianusch  SAYAH-KARADJI |/    |     /  \    | \  |  |   |  \___   |      |____|
{!pixar!unicom!sayah_k} |\    |    /----\   |  \ |  |   |      \  |      |    |
======================= | \  _|_  /      \  |   \|  \___/  ____/  \___/  |    |

gwyn@smoke.BRL.MIL (Doug Gwyn ) (02/26/89)

In article <424@unicom.UUCP> sayah_k@unicom.UUCP (KIANUSCH... Yes, Kianusch himself !!!) writes:
>Is there a way to exports system-variables from subshell, running in background
>to the main shell?

There's no (simple, portable, supported) way to alter a process's
environment variables from a subprocess.  The best you can do is
to write the information into a pipe, file, FIFO, or some such and
make the parent shell pick up that information.

Without knowing exactly why you want to do this, I cannot give more
specific advice.  It's possible that you're trying to do something
the hard way...

leo@philmds.UUCP (Leo de Wit) (02/26/89)

In article <424@unicom.UUCP> sayah_k@unicom.UUCP (KIANUSCH... Yes, Kianusch himself !!!) writes:
|Is there a way to exports system-variables from subshell, running in background
|to the main shell?
|
|I tried and tried and tried... but with no results... :-(
|

You haven't tried the following (assuming you don't need signal 5 in
the main shell). You can use it in all kinds of ways to communicate
between a parent and its child shell; I saw the idea first presented by
Maarten Litmaath to implement a 'cd with prompt-to-path conversion'
kind of cd alias for the Bourne shell.

Script started on Sun Feb 26 13:51:22 1989
philmds> trap ". .readvar" 5
philmds> trap
5: . .readvar
philmds> (echo "NEWVAR=newvalue export NEWVAR" >.readvar; kill -5 $$)&
19795
philmds> 
[1]    Done                 ( echo "NEWVAR=newvalue export NEWVAR"; kill -5 $$ )
philmds> echo $NEWVAR

philmds> echo $NEWVAR
newvalue
philmds> 

script done on Sun Feb 26 13:55:43 1989

Note the somewhat peculiar behaviour of the main shell: the trap seems to be
honoured only after execution of the next command. Maybe someone else has a
reasonable explanation of this?

    Leo.