Documented but un-obvious UNIX tricks
Mark Horton
mark at cblpf.ATT.COM
Tue Nov 14 04:54:09 AEST 1989
In article <8504 at cbmvax.UUCP> ford at cbmvax.UUCP (Michael "Ford" Ditto) writes:
>In article <23698 at cup.portal.com> thad at cup.portal.com (Thad P Floryan) writes:
>>I've been informed the "ln" trick with respect to "ls" doesn't work with:
>>
>> AT&T 386 running SysVR3.2, or
>> AT&T 3B2 600 running SysVR3.1.1
>
>The "trick" of ls looking at its invocation name was present and
>documented in 7th edition Unix, and is still in BSD. I don't know exactly
>when it was dropped, but it was not in SVR2. It's one of the few cases
>where I'm glad the Unix PC ended up with a pre-SVR2 version of a command.
>The Unix PC ls source code contains various comments and code labelled
>"UCB", and a comment: "Modified by Bill Joy and Mark Horton Sommer 1980".
I can confirm most of this, except that it wasn't in V7. There was always
a standard Berkeley enhancement where "ls" would print in columns if stdout
was a tty but (for upward compatibility with shell scripts) down the left
edge if stdout was a pipe, file, etc. Once a person has used an ls with
this feature, they usually refuse to go back to the System V release 1
notion of "always down the left edge." A typical UNIX system port with
"Berkeley enhancements" usually had vi, csh, more, and the Berkeley ls,
and maybe a few other odds and ends.
About the same time, some Bell Labs folks in IH were doing their own
enhancments. They added their own version of -F, which put brackets
around directories: "[dir]", and stars after executables. We heard
about this at Berkeley, and discovered they were using our version of
ls. We didn't care for the brackets: 14 char file names plus 2 chars
of brackets doesn't line up nicely with 16 character columns, and we
wanted the columns at 16 so we could use hardware tabs. The result
was a compromise, there was an ifdef in the code so that you could get
the IH or the UCB behavior. The last character stuff was added at the
same time, although I can't remember whose idea it was, it was heavily
used by both Berkeley and IH. (The "lf" command, in particular, is
still heavily used at IH.)
I think Bill was less enthusiastic about the last char hack, so 4BSD
wasn't distributed with the links, but 2BSD, which I handled at the
time, was.
System V has since added the -C option, which, when combined with an
alias, does the job (except that it always prints in columns, even
if you don't want it to.) System V release 4 has most of the nice
Berkeley features with -C on-default-unless-tty and -1, although I
don't think the "last char" hack was requested, so it's not there.
The simple fact is, that for any version of ls that allows multiple
option arguments (as the System V version does) an alias does this
just as well as a link, so there's no good reason to add it to the system.
Incidently, the "multi-column if tty" business is not without controversy.
Rob Pike and others at Murray Hill don't like the fact that it doesn't
do the same thing if piped somewhere. They have a point, but I think
most people feel that it's better not to break shell scripts but to have
a decent looking display on your screen (instead of zipping off the top).
The UNIX PC does not run straight System V. It runs System V release 2
plus lots of neat stuff that Conversant thought would be nice. The
Berkeley ls seems to be one thing they added. I for one appreciated
their enhancements, it made the machine a lot friendlier, and I had
to bring less personal baggage onto the system to make it usable.
By the way, I don't see the "last char hack" documented in any of my
4BSD or RDS (IH) manuals, so I'm not sure where you're looking.
Mark Horton
More information about the Unix-pc.general
mailing list