csh setenv problem

Jonathan I. Kamens jik at athena.mit.edu
Mon Aug 21 05:58:21 AEST 1989


In article <2312 at zaphod.axion.bt.co.uk> iwarner at zaphod.axion.bt.co.uk writes:
>	The Bourne Shell (sh) has an export command, which exports
>a variable to the parent shell. Csh does not have this.

  In a word, wrong.

  There is no mechanism for passing environment variables from a child
process back to its parent.  It can't be done.  Unless you hack in
some form of interprocess communication between two processes whose
source code you write yourself, so that they can pass variables back
and forth along a pipe or something, and deal with them appropriately.

  Like csh, sh has two different kinds of variables, environment
variables and local shell variables.  When you set a variable with the
command "FOO=bar", you create a local variable with that value (if the
variable did not already exist), or change the value of the local
variable (if it already existed as a local variable), or change the
value of the environment variable (if it already existed as an
environment variable).  The command "export FOO" does NOT send the
value of FOO to the parent process of the shell, it changes FOO from a
local variable into an environment variable, so that child processes
will inherit the variable.

  Observe:

Script started on Sun Aug 20 15:35:18 1989
achates% /bin/sh
$ /bin/sh			# There are now two sh's running, and
				# one is the child of the other
$ FOO=bar; export FOO
$ echo $FOO
bar				# FOO is an environment variable in
				# the child sh
$ ^D$ echo $FOO			# ^D exits from the child shell
				# The line is blank, because FOO has
$ ^Dachates% exit		# no value in the parent sh
script done on Sun Aug 20 15:36:20 1989

Jonathan Kamens			              USnail:
MIT Project Athena				432 S. Rose Blvd.
jik at Athena.MIT.EDU				Akron, OH  44320
Office: 617-253-4261			      Home: 216-869-6432



More information about the Comp.unix.questions mailing list