Subject: Re: More Bourne shell script help
To: None <netbsd-help@netbsd.org>
From: Christian Caldwell <cvcaldwell@gallie3436.ucr.edu>
List: netbsd-help
Date: 07/26/2006 12:54:22
I have a recommendation for a book chapter explaining how a
subshell works.

The book is "Learning the bash Shell" by Cameron Newham &
Bill Rosenblatt, published by O'Reilly.
http://www.oreilly.com/catalog/bash3

The webpage for this book has a link to a sample chapter. The first
three pages of this chapter have a description of why you are having
your problem, just as Johnny Billquist explained. There is a figure
that illustrate ways to run a shell script.

As one who is just beginning in shell scripting, I am finding this
book a useful resource. I also have "Classic Shell Scripting" from
the same publisher, which is equally useful and has a more complete
explanation of the . (dot) command.

I wish I had an answer to your question. I'm hoping my reference
will at least help you get it solved.

--Christian Caldwell


On Wed, Jul 26, 2006 at 08:31:36PM +0200, Johnny Billquist wrote:
> The current path, as well as all environment variables are only 
> inherited by cild processes. You can never affect the parent process.
> 
> For a shell script to affect your own environment, it must not be run as 
> a process of it's own, but instead must be run by your instance of the 
> shell.
> 
> In sh (and affiliates), this is done by running the shellscrip as:
> 
> . <script>
> 
> . is a command in sh, which does just that.
> 
> In csh you instead type "source <script>"
> 
> 	Johnny
> 
> Andy Ruhl wrote:
> >Thanks for everyone's input on my last question.
> >
> >I have the entire script written, except for the very last part.
> >
> >It parses input so that it may cd to some fairly long directory path.
> >
> >What I'm stuck on is, how to cd to that path and make it "stick" when
> >the script exits?
> >
> >What I've done is strip down everything so that, say, $dirpath is the
> >string that I need to pass to cd.
> >
> >This works inside the script:
> >
> >cd $dirpath
> >
> >However when the script exits I'm just back to the same pwd as I was 
> >before.
> >
> >I think I'm going to have to execute a new shell and pass in "cd
> >$dirpath" as a command? It would be really nice not to have to do
> >this... Any way not to? And if not, any suggestions on how I should
> >get that done?
> >
> >Thanks a bunch!
> >
> >Andy
> 
> -- 
> Johnny Billquist                  || "I'm on a bus
>                                   ||  on a psychedelic trip
> email: bqt@update.uu.se           ||  Reading murder books
> pdp is alive!                     ||  tryin' to stay hip" - B. Idol