[plug] Changing working directory from a bash script

Patrick Coleman blinken at gmail.com
Mon Jan 22 15:28:02 WST 2007


On 1/22/07, Matt Kemner <zombie at penguincare.com.au> wrote:
> On Mon, 22 Jan 2007, quoth Patrick Coleman:
>
> > I realise that this seems pretty basic, but I'm trying to change the
> > working directory from within a bash shell script and not having much
> > luck.
> >
> > restore3:~ admin$ ./somescript.sh
> > [script runs]
> > restore3:/some/directory admin$
>
> Don't execute the script (which spawns a subshell as you mentioned) but
> instead "source" the script, so the commands are run in your current
> shell.
>
> You can use either "source" or "." for short
>
> eg: restore3:~ admin$  . ./somescript.sh
> or for the full command:
> eg: restore3:~ admin$  source ./somescript.sh

Ah, brilliant. Thanks to both of you for your help.

Cheers,

Patrick



More information about the plug mailing list