On 11/12/2010 09:57 AM, Philip Webb wrote:
> There are quick'n'easy commands to goto the previous dir
> -- 'cd -' , which cb aliased as 'p' --
> & goto the next-higher dir -- 'cd ..' , which cb aliased as 's' -- ,
> but is there a way to set up a qne command to goto a parallel dir,
> eg if you're in ~/tmp goto ~/hold ( 2 of my commonly-used dirs) ?
>
> It needs to be a Bash function, so in ~/.bashrc
> I tried 'function cd2() { cd .. ; cd $1 ; }',
> so that 'cd2 hold' would take me where I wanted to go,
> but it simply dropped me in ~ , the 2nd half being ignored.
>
> It cb done with a shell var,
> ie 'function cd2() { NEWDIR=$1 ; cd .. ; cd $NEWDIR ; NEWDIR= ; }',
> which works but is a bit lengthy & could clash with an existing shell var.
>
> The elegant way is 'function cd2() { cd .. ; cd $"$1" ; }' ;
> the " ... " are essential: it fails without them or with ( ... ) instead.
>
> HTH a few others.
>
cd ${PWD/old/new}
works when you're in /some/old/tree/directory and you want to go to
/some/new/tree/directory