How Does One Change Variables That Are Set From A Sub-Shell

Randal Schwartz merlyn at iwarp.intel.com
Thu Nov 23 11:51:37 AEST 1989


In article <1989Nov21.052026.11968 at athena.mit.edu>, jik at athena (Jonathan I. Kamens) writes:
| In article <1989Nov20.190903.27550 at wucs1.wustl.edu> flan at ai.wustl.edu (Ian "No
| Excuse" Flanigan) writes:
| >	How does one pass a csh variable back to the old csh -or- grab said
| >	variable from a currently running shell and then feed it back.
| 
|   You cannot pass environment variables or shell variables from a
| sub-shell back to its parent, and you cannot (without reading the
| memory image of the running sub-process in order to find the value of
| the variable) "grab" a variable from a sub-process in order to set its
| value in another process' environment.
| 
|   The only way this would be possible is if the parent and child
| defined some special protocol (using a pipe, socket, whatever) for
| transferring variable names and values between themselves.  None of
| the "standard" shells (sh, csh, tcsh, ksh, bash, whatever) have any
| facility for doing this, at least not that I know of.

However, reaching into my bag of nifty /bin/sh tricks, I could do
something like:

trap '. $HOME/.doit; /bin/rm -f $HOME/.doit' 4
(/my/background/process $$)&

where "/my/background/process" is responsible for putting some
/bin/sh commands, like:

PS1="${PS1L}YOU HAVE MAIL ${PS1R}"

into $HOME/.doit, and sending the shell (as passed by the first arg, a
signal 4).

The detailed implementation is left as an exercise to the reader. :-)

Just another shell wizard,



More information about the Comp.unix.questions mailing list