Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!think.com!mintaka!mit-eddie!uw-beaver!cornell!rochester!pt.cs.cmu.edu!dsl.pitt.edu!pitt!darth!investor.pgh.pa.us!rbp From: rbp@investor.pgh.pa.us (Bob Peirce #305) Newsgroups: comp.unix.shell Subject: Re: Csh question: Doing cd .. from a symbolically linked directory Message-ID: <1990Nov3.002545.4005@investor.pgh.pa.us> Date: 3 Nov 90 00:25:45 GMT Reply-To: rbp@investor.pgh.pa.us (Bob Peirce #305) Organization: Cookson, Peirce & Co., Pittsburgh, PA Lines: 68 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 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