Changing the environment in sh

Steven M. List itkin at mrspoc.UUCP
Sun Sep 4 11:07:00 AEST 1988


In article <59 at csnz.nz> paul at csnz.UUCP (Paul Gillingwater) writes:
> I've Read The FM's, but I must be a bit dim - how do I change an
> environment variable, e.g. PATH, using a /bin/sh script, and have
> those changes effective in my login shell?
> 
You're not dim, just apparently a novice with the shell.  This is one of
the first difficult lessons of shell programming.  You cannot change the
value of a variable (environment or otherwise) from a subshell, since
the environment of a superior shell is not available to the subshell.
The only way to do this is with the "." (dot) command which can loosely
be understood to mean "read in the following file (using PATH if
necessary) and execute it as if I had typed the commands directly into
my keyboard".  Of course, if you include the dot command in a shell
script, it will execute the commands AS IF THEY WERE PART OF THE CALLING
SCRIPT.  There is NO OTHER WAY to change shell environment variables.
-- 
*  Steven List @ Transact Software, Inc.
*  {coherent,mips,ubvax}!mrspoc!itkin
*  Voice: (415) 961-6112



More information about the Comp.unix.xenix mailing list