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

Re: bash: can I cd from a script



Dave Carrigan wrote:

On Wed, 2003-07-23 at 07:36, David Z Maze wrote:

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.

If your script is really complicated, alter it a bit so it prints out
the directory to change to and you can still do it as a function:

mycd() {
 cd `my-big-script "$*"`
}

my-big-script:
#! /bin/sh

# Do lots of stuff
echo /the/new/directory

It works ... !, I had in desperation defined an alias
alias test='source script' which also worked but was very messy, I prefer your idea, and it is now in situ !

Dave



Reply to: