Thread View: comp.unix.shell
6 messages
6 total messages
Started by Jerry Liebelson
Wed, 24 Oct 1990 15:01
Csh question: Doing cd .. from a symbolically linked directory
Author: Jerry Liebelson
Date: Wed, 24 Oct 1990 15:01
Date: Wed, 24 Oct 1990 15:01
34 lines
1653 bytes
1653 bytes
*SEND REPLIES TO: uunet!slcpi!slhisc!jerry
Organization: Shearson Lehman Brothers, Inc.
------------------------------------------------------------------------------
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?
I tried setting the hardpaths variable but that just changes the output
of pwd when I am in /tmp/c (displaying "/tmp/a/b" instead of "/tmp/c").
COMMENT:
I know the behavior I want can be achieved in the Korn Shell. But I
am stuck with the Csh for now.
--
Jerry Liebelson uunet!slcpi!slhisc!jerry
Distributed Infrastructure (212) 341-3166 FAX: (212) 528-0101
Shearson Lehman Brothers, Inc.
--
Jerry Liebelson uunet!slcpi!slhisc!jerry
Distributed Infrastructure (212) 341-3166 FAX: (212) 528-0101
Shearson Lehman Brothers, Inc.
Re: Csh question: Doing cd .. from a symbolically linked directory
Author: Maarten Litmaath
Date: Wed, 24 Oct 1990 23:39
Date: Wed, 24 Oct 1990 23:39
61 lines
1647 bytes
1647 bytes
In article <JERRY.90Oct24110101@sky.slhisc.uucp>, jerry@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
Re: Csh question: Doing cd .. from a symbolically linked directory
Author: Tero Kivinen
Date: Thu, 25 Oct 1990 10:51
Date: Thu, 25 Oct 1990 10:51
11 lines
1332 bytes
1332 bytes
In article <JERRY.90Oct24110101@sky.slhisc.uucp> jerry@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.
--
______ ______ _ , !Tero_Kivinen@hut.FI ! Work : +358-0-451 4032 !
/ / ' ) / !Tero Kivinen ! Voice: +358-0-523 542 !
--/ --/ /-< ! ! Data : +358-0-524 207 !
(_/ (_/ / ) +---------------------+------------------------+
Re: Csh question: Doing cd .. from a symbolically linked directory
Author: Maarten Litmaath
Date: Thu, 25 Oct 1990 19:08
Date: Thu, 25 Oct 1990 19:08
26 lines
1613 bytes
1613 bytes
In article <KIVINEN.90Oct25125016@deathstar.hut.fi>, kivinen@cs.hut.fi (Tero Kivinen) writes: )In article <JERRY.90Oct24110101@sky.slhisc.uucp> ) jerry@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
Re: Csh question: Doing cd .. from a symbolically linked directory
Author: Maarten Litmaath
Date: Fri, 26 Oct 1990 19:09
Date: Fri, 26 Oct 1990 19:09
16 lines
1270 bytes
1270 bytes
Here's a slight improvement; check the output of `cd /'; furthermore you won't get into trouble if you accidentally type `cd foo/ bar' or if there is a subdirectory `0' and you type `cd0'. --------------------cut here-------------------- alias cd 'set tmp=(\!*); eval _cd_$#tmp $cwd \!*//. ../ ~; echo $cwd' alias _cd_0 'chdir \!$' alias _cd_1 'if (x\!:2 !~ x../*) set status=1'\ '&& eval _cd_x /\!^:h \!:2-:s-../--'\ '|| chdir \!:2:h' alias _cd_x 'if (x\!:2 !~ x../*) set status=1'\ '&& eval _cd_x /\!^:h \!:2*:s-../--'\ '|| chdir \!^/\!:2:h' alias pwd 'echo $cwd' --------------------cut here-------------------- -- Waiting for this to work: cat /internet/cs.vu.nl/finger/maart
Re: Csh question: Doing cd .. from a symbolically linked directory
Author: Bob Peirce #305
Date: Wed, 31 Oct 1990 16:42
Date: Wed, 31 Oct 1990 16:42
17 lines
1372 bytes
1372 bytes
In article <8060@star.cs.vu.nl> maart@cs.vu.nl (Maarten Litmaath) writes: >--------------------cut here-------------------- >alias cd 'set tmp=(\!*); eval _cd_$#tmp $cwd \!*//. ../ ~; echo $cwd' >alias _cd_0 'chdir \!$' >alias _cd_1 'if (x\!:2 !~ x../*) set status=1'\ > '&& eval _cd_x /\!^:h \!:2-:s-../--'\ > '|| chdir \!:2:h' >alias _cd_x 'if (x\!:2 !~ x../*) set status=1'\ > '&& eval _cd_x /\!^:h \!:2*:s-../--'\ > '|| chdir \!^/\!:2:h' >alias pwd 'echo $cwd' >--------------------cut here-------------------- What do you do if your csh doesn't have eval and doesn't set cwd? -- Bob Peirce, Pittsburgh, PA 412-471-5320 ...!uunet!pitt!investor!rbp rbp@investor.pgh.pa.us
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads