Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!seismo!mcvax!enea!zyx!aj From: aj@zyx.UUCP (Arndt Jonasson) Newsgroups: comp.unix.wizards Subject: Re: Symbolic Links Message-ID: <1276@zyx.UUCP> Date: Wed, 2-Sep-87 15:51:36 EDT Article-I.D.: zyx.1276 Posted: Wed Sep 2 15:51:36 1987 Date-Received: Sat, 5-Sep-87 16:37:06 EDT References: <8731@brl-adm.ARPA> <2789@ulysses.homer.nj.att.com> <1781@munnari.oz> <6342@brl-smoke.ARPA> <2268@xanth.UUCP> Reply-To: aj@zyx.UUCP (Arndt Jonasson) Organization: ZYX Sweden AB, Stockholm Lines: 127 In article <2268@xanth.UUCP> kyle@xanth.UUCP (Kyle Jones) writes: >In article <6342@brl-smoke.ARPA>, gwyn@brl-smoke.ARPA (Doug Gwyn ) writes: >> In article <8137@mimsy.UUCP> chris@mimsy.UUCP (Chris Torek) writes: >> >It may be convenient, but it does not feel like Unix. >> >> As with text editors, it all depends on what you've gotten >> used to. Personally I can't stand symlinks making .. act >> like a global jump to a distant place in the hierarchy. > >Indeed it does depend on your point of view. I see symlinks as the >global jump to the distant place in the hierarchy, not "..". This >would be readily apparent if the C shell and other shells that keep >a 'current working directory' variable weren't ignorant of symlinks. I think that most people's problems with the way symbolic links are now (i.e. in BSD) arise in interactive use, i.e. when using the 'cd' command in the shell. The only times when I have been irritated by symbolic links are when I have done 'cd ..' from a directory which I reached by doing 'cd' on a link, with the known result. Mostly, I detect this after the very next command. No big deal (this is only my personal opinion, of course). Rather than 'fix' the semantics of '..', the appropriate mnemonic command should be used; either 'up' or 'back', depending on what you want ('bk' may be more appropriate, this being Unix). Additionally, the 'cd' command can be made more talkative when it encounters a symbolic link. Below is a program that some may find useful. /* Public domain - linkp.c - for BSD systems Author: Arndt Jonasson - 870902 This program accepts zero or one arguments. In the case of one argument, the argument is printed out again on standard output. As a side-effect, any symbolic links encountered while traversing the argument are printed on standard error. The intended use is in a csh alias, such as: % alias cd 'cd `linkp \!*`' Then % cd ~me/sys may print out [/usr/users/me -> /dsk1/users/me] [/usr/users/me/sys -> /usr/include/sys] This should reduce the risk of one's being unpleasantly surprised when doing 'cd ..' to a minimum. */ #include #include #define TRUE 1 #define FALSE 0 #define MAXLEN 1024 main (argc, argv) int argc; char *argv[]; { int len; char path[MAXLEN]; char *cp; char c; if (argc < 2) /* No argument, nothing to do */ exit (0); len = strlen (argv[1]); /* If there isn't a '/' at the end */ sprintf (path, /* of the pathname, add one */ "%s%s", argv[1], (len > 0 && argv[1][len-1] != '/') ? "/" : ""); cp = path; while (c = *cp++) /* Check each character of the */ /* pathname */ { if (c == '/') /* A slash: check whether this */ /* partial pathname is a link */ { int n; /* n is the length of the link text */ char buf1[MAXLEN]; /* buf1 holds the potential link */ char buf2[MAXLEN]; /* buf2 will hold its link text */ cp[-1] = '\0'; /* Zap away the '/' temporarily */ strcpy (buf1, path); /* Copy the pathname up to the */ /* current '/' into the working */ /* buffer */ cp[-1] = '/'; /* Put back the '/' */ n = readlink (buf1, buf2, MAXLEN); if (n > 0) /* Is this pathname a link? */ { fprintf (stderr, "[%s", buf1); do /* Yes, follow the link */ { fprintf (stderr, " -> %.*s", n, buf2); buf2[n] = '\0'; /* End the link text properly */ strcpy (buf1, buf2); /* and copy it into buf1 */ n = readlink (buf1, buf2, MAXLEN); /* Is it a link itself? */ } while (n > 0); fprintf (stderr, "]\n"); } } } puts (argv[1]); /* Send the original argument to */ /* stdout */ exit (0); } -- Arndt Jonasson, ZYX Sweden AB, Styrmansgatan 6, 114 54 Stockholm, Sweden Mail address: ...!seismo!mcvax!zyx!aj = aj@zyx.SE