[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: using cd is shell script



On Sun, Aug 26, 2001 at 05:26:36PM -0700, bob parker scribbled...
> Hi all, 
> being a lazy typist i have writen a little script that 
> goes like this: 
>  
> #! /bin/bash 
> #     go-xxx where xxx is the last dir in along chain 
>  
> cd /some long dir chain/xxx 
>  
>  
> My question is, how can i make the change persist 
> after the script is done 
The why of it:
When you execute a script it inherits the environment of the shell, and runs.
It does not affect the environment of the shell.

You can change this by using "." or 'source'. If you typed:
$ . go-bin 
(assuming go-bin contains "cd /usr/local/bin"), your directory would change.
You can combine this with an alias. Name your script "chdir-bin", then in your
.bashrc put:
alias go-bin=". $HOME/scripts/chdir-bin" # Or wherever you keep it.
Then you just type "go-bin" at the shell, and bingo! You can also have these
scripts accept parameters to give you greater flexibility.



Reply to: