Csh question: Doing cd .. from a symbolically linked directory
Maarten Litmaath
maart at cs.vu.nl
Thu Oct 25 09:39:16 AEST 1990
In article <JERRY.90Oct24110101 at sky.slhisc.uucp>,
jerry at slhisc.uucp (Jerry Liebelson) writes:
)...
) SITUATION:
)
) 1. cd /tmp
) 2. mkdir -p a/b
) 3. ln -s a/b c
)
) PROBLEM:
)
) 1. cd /tmp/c
) 2. pwd (output is "/tmp/c")
) 3. cd ..
) 4. pwd (output is "/tmp/a", not "/tmp" ! )
)
) QUESTION:
) 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?
Yes:
alias cd 'cd `xcd $cwd \!*`'
...where `xcd' is the following shell script, located somewhere in your
PATH. (You may have to change the `cd' in the alias to `chdir'.)
--------------------cut here--------------------
#!/bin/sh
#
# alias cd 'cd `xcd $cwd \!*`'
case $# in
1)
echo $HOME
exit 0
;;
2)
case $2 in
/*)
echo "$2"
exit 0
;;
*..*)
;;
*)
echo "$1/$2"
exit 0
esac
esac
# /a/b/c/symlink1/symlink2/../../src -> /a/b/c/src
SED='
: loop
s|/[^/]*/\.\.||g
t loop
'
echo "$1/$2" | sed "$SED"
--------------------cut here--------------------
--
Waiting for this to work: cat /internet/cs.vu.nl/finger/maart
More information about the Comp.unix.shell
mailing list