=============================== Ottawa Canada Linux Users Group =============================== Title: "Unix Mis-conceived" - or - "Things that don't work the way you think they do." Speaker: Ian! D. Allen Algonquin College National Capital FreeNet -------------------------------------------------------------------- 0) Unix History - Seventh Edition -------------------------------------------------------------------- Slide: UnixHistory.pnm PDP-11 Unix - Seventh Edition [circa 1978] http://museum.sysun.com/museum/u7conn.html - stty erase ^H kill ^U - /bin/1 - /usr/games/fortune - /usr/games/banner - /usr/games/wumpus - make love - rm God - ar t God - sleep with me - look into "my eyes" - lost - awk x - no [ command in /bin - ln /bin/test [ - ./[ 1 = 1 - [ 1 = 1 - if [ 1 = 1 ] ; then - no STTY command in /bin - tail but not head -------------------------------------------------------------------- 1) The One True Unix File System Diagram -------------------------------------------------------------------- All the Unix textbooks draw a nice little tree of the Unix file system, with the root at the top and file names at the bottom, and thus completely mislead people about how the file system actually works. Nobody who learned Unix from such a diagram can understand how Unix file links work. I'll draw the real diagram, and you can take it home and paste it over all the other diagrams in all your Unix texts. Slide: FSdiagram.pnm Slide: UsingLinks.pnm Slide: ln.pnm -------------------------------------------------------------------- 2) Stupid Interactive Bourne Shell Tricks -------------------------------------------------------------------- My Algonquin classes remain somewhat mystified by the way the shell handles redirection, expands variables, and locates file names. I'll give a quick demo of the basics, including some things that might surprise you. Some important differences will be noted for CSH users. Yes, you can easily fill your disk. if grep alsdkfj /etc/passwd ; then echo found ; fi if grep idallen /etc/passwd ; then echo found ; fi if [ 1 = 1 ] ; then echo hi echo ho date fi >out - compare with CSH $ echo a b c >x $ echo a b >x c $ echo a >x b c $ echo >x a b c $ >x echo a b c $ >x - try it in CSH with an alias $ echo hi | echo ho $ echo hi >x | echo ho >y $ cat x y $ x=0 $ echo $x $ x=1 | x=2 $ echo $x - try it in CSH $ sleep 99 & $ sleep 99 & $ sleep 99 & $ sleep 99 & $ jobs >x $ jobs | wc - try it in CSH $ echo */. $ echo .??* $ echo * >x % echo * >x -------------------------------------------------------------------- 3) Programming as Hacking Until it Works (most of the time) -------------------------------------------------------------------- I found a pile of bugs in the original (Bill Joy) C Shell while avoiding working on my Masters Thesis at Waterloo in the early 1980's, and so I went about trying to fix them. The resulting shell ("itcsh" - Ian's Tenex CSH) was in use at Waterloo for many years. I'll talk a bit about just how awful C shells are for writing programs even 20 years later. Don't do this at home, kids. Subject: redirection always happens in single-line "if" if ( 1 ) echo hi > date if ( 0 ) echo hi > date The file date is created empty. Subject: extra next level when nested single-line IF line ends in THEN Slide: ifnest.csh Any IF line that ends in THEN is taken as another nesting level, and requires a corresponding ENDIF: if ( 0 ) then if ( 0 ) echo This line ends with then endif echo You do not see this. endif # This shouldn't be needed; but it is. echo Now you do. Subject: Redirection ignored inside if ( { cmd >xxx } ) .... % if ( { date >out } ) echo hi Sun Apr 14 13:24:31 EDT 2002 hi The shell does not set up its file descriptors for the forked command. The redirection is completely ignored. Subject: Can't redirect output of "source" % echo "date" >file % source file >output Thu Sep 3 17:47:19 EDT 1987 Subject: nice is not cumulative % nice date % nice nice date Both have a nice of 4; nice does not accumulate. Subject: GLOB not applied to names in setenv or unsetenv % setenv `echo abc` bleen % printenv | grep bleen It doesn't set abc, it sets the nasty variable: `echo abc` Subject: CSH doesn't handle EXIT when it sees it. % date; exit 99 ; date ; date Wed Mar 14 19:21:51 EST 1984 Wed Mar 14 19:21:52 EST 1984 Wed Mar 14 19:21:53 EST 1984 The shell doesn't flush pending input when the EXIT is seen. The shell then exits with status 0 instead of status 99. Subject: C Shells don't parse when looking for labels. Slide: onintr.csh The shells just look at the first word on each line. You can cause the shell to branch in to the middle of a HERE document: #!/bin/csh -f onintr quit sleep 999 cat << EOF quit: echo Amazing how this prints. exit 88 # this exit is taken when break is hit EOF quit: echo You never get here. Subject: aliases aren't seen after redirection % date >x % >x date % alias foo date % foo >x % >x foo foo: Command not found. Subject: Re: Using > vs. | on shell built-in commands. CSH cannot put the output of the JOBS command into a pipe. In fact, the output is going into the pipe, but the output is empty. You couldn't know this, but these shells implement piped built-in commands by forking the shell to create an independent process for which the main shell can wait. But the internal process table is cleaned out after a fork(), since a forked shell is just like a subshell and must have its own clean process table in which to enter its own running jobs. So by the time the JOBS command executes, it's in a child shell that has no jobs running. Hence, the output is empty. "echo `jobs`" and "( jobs )" are both empty, for the same reason. From: matt@prism.UUCP Subject: Pointless csh puzzle Here's a pointless little csh puzzle: In the c-shell, it is possible to set and environment variable whose name consist of more than one word, in the obvious way: % setenv "FOO BAR" quux The printenv builtin will show it residing happily in the environment. Now for the puzzle: can anyone find a way to GET TO the value of this variable, using only csh builtins? In other words, is there an such that % echo will print "quux" on the screen, where is formed only from csh commands? From tim@ISM780B.UUCP Wed Nov 20 18:00:00 1985 Subject: Re: C-shell puzzles Here's another good C shell quirk: $ echo foo foo $ repeat 3 echo foo foo foo foo $ repeat 3 repeat 3 echo foo foo foo foo foo foo $ repeat $N repeat $M echo foo # $N and $M are integers [ $N + $M - 1 foo's ] $ repeat $N1 repeat $N2 ... repeat $Nk echo foo [ $N1 + $N2 + ... + $Nk - k + 1 foo's ] $ From: Ray Butterworth Subject: CSH history reading takes '#' as a comment % echo a b # c d a b # c d % exit % login % history ... 99 echo a b '#' indicates a comment when reading from a shell script file, and of course CSH thinks it is reading from a file when it reads the history back in. Subject: Redirected input to built-in functions misbehaves badly % date | echo hi hi % % jobs [1] + Running date | Note the duplicate prompt and spurious job entry. % % date | echo hi hi % % date | echo hi hi % % jobs [1] + Running date | [2] - Running date | [3] Running date | % fg date | % fg date | fg: No such job (badjob). % fg [tcsh shell hangs here in an infinite loop] Just a general mess of mishandled processes. -------------------------------------------------------------------- 4) Don't Throw Anything Out (Anecdote Section) -------------------------------------------------------------------- - XFree86 is 10 years old! I started using the X window system when it arrived at UofWaterloo in the 1980's, first with X10 [not the cameras] and then with X11. A feature that X10 had was the ability for an icon to be changed when the xterm window associated with it had output. This feature was lost in X11, so I dug into the code and added it back at Waterloo. Little did I know where it would go. - X10 xterm puts "***" into icons when output arrives - 1990 I write an xterm patch at UofWaterloo for X11R4 Slide: xterm.r4.diffs - 1991 patch posted to comp.windows.x for X11R5 Slide: xterm.r5.diffs - somewhere mid-1990's I start using stock Ultrix xterm - no more "***" - 2000 Mandrake 7 installed (RH 6.2) - suddenly "***" is back! - my .Xresources file never had it removed (since 1990!) >From: Thomas Dickey Sep 17, 2000 >It's in the changelog - I probably don't have the original email: > > Patch #72 - 1998/4/17 - XFree86 3.9Ag and 3.3.2 > > This is a patch from Chris Siebenmann , > which I have cleaned up a little, and integrated into the configure > script. > > From his description: > > This set of patches is the latest incarnation of patches originally > written by Ian! D Allen, then of the University of Waterloo and now > of who knows where; I have been carrying them forward from xterm to > xterm ever since about X11R4. What they do is add an option so that > when an iconified xterm receives output it prepends '*** ' to its > icon title and (optionally) beeps the bell; deiconifying the xterm > removes the '*** '. Over the years I've found this to be incredibly > convenient for monitoring all sorts of low-activity things. > >I don't know much about the BSD sources. Though I've used xterm for some >time longer, I didn't get interested in building it til around 1995.