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

Re: bash: can I cd from a script



Colin Watson <cjwatson@debian.org> writes:

> On Wed, Jul 23, 2003 at 11:17:58AM +0100, David selby wrote:
>> I have a script to show a certain directory, it would be great if that 
>> script could change my pwd to that directory.
>> 
>> Inside my script is a cd /usr/lo....., however since the script 
>> automaticly runs in a subshell, when it ends my directory has not changes.
>
>> source <scriptname> works but is clumbs
>
> '. <scriptname>' works and is less clumsy (not to mention less
> bash-specific). It's probably the best you've got.

Depending on how complicated the script is, rewriting it as a shell
function might be appropriate.  You could add to your .bashrc file
something like

  cdls() { cd "$1"; ls; }

and then "cdls foo" would change directories to foo and list it.

-- 
David Maze         dmaze@debian.org      http://people.debian.org/~dmaze/
"Theoretical politics is interesting.  Politicking should be illegal."
	-- Abra Mitchell



Reply to: