[plug] Changing working directory from a bash script

Matt Kemner zombie at penguincare.com.au
Mon Jan 22 15:00:53 WST 2007


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

Kind Regards,

 - Matt Kemner             Perth:     Tel 08 9322 3444 Fax 08 9221 3444
  Penguin Care             Adelaide:  Tel 08 8311 1144 Fax 08 8311 1177
  Linux & VoIP Specialist  Melbourne: Tel 03 8648 6644 Fax 03 8648 6677
  Mobile: 04 2022 3444     Brisbane:  Tel 07 3337 9988 Fax 07 3337 9977




More information about the plug mailing list