Csh question: Doing cd .. from a symbolically linked directory

Maarten Litmaath maart at cs.vu.nl
Fri Oct 26 05:08:23 AEST 1990


In article <KIVINEN.90Oct25125016 at deathstar.hut.fi>,
	kivinen at cs.hut.fi (Tero Kivinen) writes:
)In article <JERRY.90Oct24110101 at sky.slhisc.uucp>
)	jerry at slhisc.uucp (Jerry Liebelson) writes:
)>      Is there a way to set things in the csh such that when I do the cd ..
)>    from /tmp/c, I will end up in /tmp and not in /tmp/a?
)
)Try alias .. 'cd /$cwd:h' in your .cshrc, and then typing .. works.
)This will work in csh or in tcsh.

But that doesn't deal nicely with `cd ../../foo/bar'...
Following is a solution that does _and_ is completely builtin!
Piece of cake right?  :-)

--------------------cut here--------------------
alias	cd	'set tmp=(\!*); eval cd$#tmp $cwd \!*/. ../ ~; echo $cwd'
alias	cd0	'chdir \!$'
alias	cd1	'if (x\!:2 !~ x../*) set status=1'\
		'&& eval cd2 /\!^:h \!:2-:s-../--'\
		'|| chdir \!:2'
alias	cd2	'if (x\!:2 !~ x../*) set status=1'\
		'&& eval cd2 /\!^:h \!:2*:s-../--'\
		'|| chdir \!^/\!:2'
--------------------cut here--------------------
--
Waiting for this to work: cat /internet/cs.vu.nl/finger/maart



More information about the Comp.unix.shell mailing list