cd in the background?

Robert Earl rearl at gnu.ai.mit.edu
Thu May 2 05:26:11 AEST 1991


In article <27756 at hydra.gatech.EDU> dsm at prism.gatech.EDU (Daniel McGurl) writes:
|   In article <gheim.910430165314 at lab14.eng.auburn.edu> gheim at eng.auburn.edu (Greg Heim) writes:
|   >I posted this question to comp.unix.questions and got no response...

comp.unix.questions needs a lobotomy if nobody could answer it.
That's a perfectly fine place to ask.  Perhaps your news software is
faulty.

|   >The other day I accidentally entered  
|
|   >   cd /new/dir &
|
|   >and my directory remained unchanged.  Can anyone explain what is going on here?

`cd' is a builtin command.  The `&' forced the shell to spawn a child
and execute the cd in a copy of itself, making this an effective no-op
because a child cannot change a parent's working directory.

|   Here's the problem.  Backgrounding creates a new shell for the process to
|   execute in.  The process executes and does the CD in the newly spawned 
|   shell.  Then the shell dies and the old shells variable remain the way
|   they were.

It has nothing to do with shell variables.



More information about the Comp.unix.wizards mailing list