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

Bob Peirce #305 rbp at investor.pgh.pa.us
Fri Nov 2 00:39:09 AEST 1990


My brain damaged csh lacks eval and it doesn't set cwd.  It also runs on
an Altos with worknet -- top level directories may be / or @node. 
However, we do have symbolic links, so here is my solution.  I have been
hacking on this for about the last day or two.  It now handles 99% of
anything we might want to do here.  I would dearly love to know how I
can improve it. 

#  Handle typical .. moves from a symbolically linked directory
#  You can go home, rel, abs, .. or ../something.  That's it.
#  On an Altos with worknet, / may also be @node
#  Some aliases may add extraneous /s so we have to squeeze them
#  Logic is to check if you are going home.  If not, check the first
#  char of the arg to see if it is dot, /,  or  @.
#  If we lead off with a dot and the arg is the same as the tail of
#  the arg we are just doing ..  Otherwise we are doing ../something.
#  If we .. all the way to /, we have to set /.
#  If we lead off with  / or @ it is absolute.
#  If we do not lead off with dot, / or @ it is relative so
#  we append the arg to $cwd/.
set cwd = `pwd`
alias	cd	'\\
	set nwd;\\
	set tmp;\\
	set tgt = \!*;\\
	if (x\!* == "x") set nwd = $home;\\
	if (x$nwd != x$home) set tmp = `echo \!* | cut -c1`;\\
	if ("x\$tmp" == 'x\\\\.' && $tgt == $tgt:t) set nwd = $cwd:h;\\
	if ("x\$tmp" == 'x\\\\.' && $tgt != $tgt:t) set nwd = $cwd:h/$tgt:t;\\
	if ("x\$tmp" == 'x\\\\.' && $nwd == "") set nwd = /;\\
	if (x$nwd != x$home && x$tmp == 'x/' || x$tmp == 'x@') set nwd = \!*;\\
	if (x$nwd == "x" && \!* != '..') set nwd = $cwd/\!*;\\
	chdir $nwd;\\
	set cwd = `echo $nwd | tr -s '/'`'

-- 
Bob Peirce, Pittsburgh, PA				  412-471-5320
...!uunet!pitt!investor!rbp			rbp at investor.pgh.pa.us



More information about the Comp.unix.shell mailing list