[comp.unix.wizards] cd in the background?

gheim@eng.auburn.edu (Greg Heim) (05/01/91)

Howdy,

I posted this question to comp.unix.questions and got no response...
The other day I accidentally entered  

   cd /new/dir &

and my directory remained unchanged.  Can anyone explain what is going on here?


Thanks for any insight,

Greg


x--x--x--x--x--x--x--x--x--x--x--x--x--x--x--x--x--x--x--x--x--x--x--x--x--x
|  Name: Greg Heim                                                         |
|  Address: gheim@eng.auburn.edu                                           | 
|  Description: Student, Applied Mathematics, Gasp!                        |
|  Catchy Net Phrase: Ignorance is a bitch.                                |
x--x--x--x--x--x--x--x--x--x--x--x--x--x--x--x--x--x--x--x--x--x--x--x--x--x

dsm@prism.gatech.EDU (Daniel McGurl) (05/01/91)

In article <gheim.910430165314@lab14.eng.auburn.edu> gheim@eng.auburn.edu (Greg Heim) writes:
>I posted this question to comp.unix.questions and got no response...
>The other day I accidentally entered  

>   cd /new/dir &

>and my directory remained unchanged.  Can anyone explain what is going on here?

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.

-- 
Danny McGurl                               "How straightforward the game
Office of Information Technology and       when all its rules are respected."
Information and Computer Science Major at:
Georgia Institute of Technology                     ARPA: dsm@prism.gatech.edu

rearl@gnu.ai.mit.edu (Robert Earl) (05/02/91)

In article <27756@hydra.gatech.EDU> dsm@prism.gatech.EDU (Daniel McGurl) writes:
|   In article <gheim.910430165314@lab14.eng.auburn.edu> gheim@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.