[ale] cd in bash or ksh, how to do this

Narahari 'n' Savitha savithari at gmail.com
Wed Sep 22 12:25:48 EDT 2010


Thank you. It is what I was looking for.

How do you tell the shell use the cd function instead of the inbuild cd.

-Narahari

On Mon, Sep 20, 2010 at 5:00 PM, Don Lachlan <ale-at-ale.org@
unpopularminds.org> wrote:

> On Fri, Sep 17, 2010 at 5:44 PM, Narahari 'n' Savitha
> <savithari at gmail.com> wrote:
> > I remember using cd in the following way.
> >
> > $pwd
> > /this/is/the/folder/that/all/are/in/now
> >
> > The folder structure till the that is
> > $ls /this/is/the/folder/that/
> >
> > all
> > males
> > females
> >
> > I was able to do this
> >
> > $cd all males
> > $pwd
> > /this/is/the/folder/that/males/are/in/now
> > $cd males females
> > /this/is/the/folder/that/females/are/in/now
>
> If you're trying string replacement in bash:
>
> bash$ cd /usr/lib
> bash$ pwd
> /usr/lib
> bash$!?cd?:s/usr/var/
> bash$ pwd
> /var/lib
>
> I don't know of a 'cd' specific one to do that, but it's simple to
> write a bash function:
>
> function cd () {
>  if [ -n "$2" ] ; then
>    nd=`pwd | sed 's/'$1'/'$2'/'`
>    builtin  cd $nd
>  else
>    builtin cd $1
>  fi
> }
>
> bash$ cd /usr/lib/
> bash$ pwd
> /usr/lib
> bash$ cd usr var
> bash$ pwd
> /var/lib
>
> -Lachlan
>  _______________________________________________
> Ale mailing list
> Ale at ale.org
> http://mail.ale.org/mailman/listinfo/ale
> See JOBS, ANNOUNCE and SCHOOLS lists at
> http://mail.ale.org/mailman/listinfo
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.ale.org/pipermail/ale/attachments/20100922/ee5ecd50/attachment.html 


More information about the Ale mailing list