Thread View: comp.unix.shell
1 messages
1 total messages
Started by Bob Peirce #305
Sat, 03 Nov 1990 00:25
Re: Csh question: Doing cd .. from a symbolically linked directory
Author: Bob Peirce #305
Date: Sat, 03 Nov 1990 00:25
Date: Sat, 03 Nov 1990 00:25
68 lines
2363 bytes
2363 bytes
Yesterday I posted a note on the problem facing this user of csh who
has sym links but lacks eval and a setting mechanism for cwd. After
thinking about it more today I decided the best solution was to build
the path with a small C program and to use a short alias to drive it.
The results follow. The C program could be made smaller and, possibly
faster by not using stdio, but this works. Setting the sticky bit
also might help.
============================== csh alias ==============================
# Handle typical .. moves from a symbolically linked directory
set cwd = `/bin/pwd`
alias pwd 'echo $cwd'
alias rpwd /bin/pwd
alias rcd chdir
alias cd '\\
if (\!* == "") set tmp = $home;\\
if (\!* != "") set tmp = `glob \!*`;\\
set cwd = `/usr/local/lib/chd $cwd $tmp`;\\
chdir $cwd'
============================== C program ==============================
/* @(#) chd.c
C program for cd
*/
#include <stdio.h>
main(argc,argv)
char **argv;
int argc;
{
int i, j;
char path[256];
if (argc != 3) exit(); /* silent failure */
/* Top dir in Altos Worknet may be @node */
if (argv[2][0] == '/' || argv[2][0] == '@')
printf ("%s\n", argv[2]);
else {
strcpy(path, argv[1]);
strcat(path, "/");
strcat(path, argv[2]);
i = j = 0;
while (path[i] != '\0') {
if ( j != i) path[j] = path[i];
if (path[i] == '.' && path[i+1] == '.') {
++i;
if (j >= 2) {
j -= 2;
while (path[j--] != '/')
;
}
else j = -1;
}
++i;
++j;
}
if (j == 0)
strcpy (path, "/");
else
path[j] = '\0';
printf ("%s\n", path);
}
}
============================== END ==============================
--
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