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

Richard Bronosky Richard at Bronosky.com
Wed Sep 22 13:45:31 EDT 2010


This is a great idea! I'm adding this to my ~/.bash_aliases file:
function ced () { nd=$(pwd | sed "$@") && cd $nd; }

On Wed, Sep 22, 2010 at 12:25 PM, Narahari 'n' Savitha
<savithari at gmail.com> wrote:
> 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 at 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
>
>
> _______________________________________________
> 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
>
>



-- 
.!# RichardBronosky #!.



More information about the Ale mailing list