[ale] cd in bash or ksh, how to do this
Don Lachlan
ale-at-ale.org at unpopularminds.org
Mon Sep 20 17:00:48 EDT 2010
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
More information about the Ale
mailing list