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