Subject: Re: More Bourne shell script help
To: Andy Ruhl <acruhl@gmail.com>
From: Johnny Billquist <bqt@update.uu.se>
List: netbsd-help
Date: 07/26/2006 20:31:36
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