158 csh, pipes, and find (BTW, your typical TeX source file gets classified as “ascii text” rather than “English text,” but I digress…) words.h.~1~: ascii text words.h: English text Perhaps I added some comments to words.h after version 1? But I saved the best for last: arc.h: shell commands Makefile: [nt]roff, tbl, or eqn input text Both wildly wrong. I wonder what would happen if I tried to use them as if they were the kinds of program that the ‘file’ program assigns them? —Alan Shell Variables Won’t Things could be worse for Alan. He could, for instance, be trying to use shell variables. As we’ve mentioned before, sh and csh implement shell variables slightly differently. This wouldn’t be so bad, except that semantics of shell vari- ables—when they get defined, the atomicity of change operations, and other behaviors—are largely undocumented and ill-defined. Frequently, shell variables behave in strange, counter-intuitive ways that can only be comprehended after extensive experimentation. Date: Thu, 14 Nov 1991 11:46:21 PST From: Stanley’s Tool Works lanning@parc.xerox.com Subject: You learn something new every day To: UNIX-HATERS Running this script: #!/bin/csh unset foo if ( ! $?foo ) then echo foo was unset else if ( "$foo" = "You lose" ) then echo $foo
Shell Programming 159 endif produces this error: foo: Undefined variable. To get the script to “do the right thing,” you have to resort to a script that looks like this: #!/bin/csh unset foo if ( ! $?foo ) then echo foo was unset set foo else if ( "$foo" = "You lose" ) then echo $foo endif [Notice the need to ‘set foo’ after we discovered that it was unset.] Clear, eh? Error Codes and Error Checking Our programming example glossed over how the file command reports an error back to the shell script. Well, it doesn’t. Errors are ignored. This behavior is no oversight: most Unix shell scripts (and other programs as well) ignore error codes that might be generated by a program that they call. This behavior is acceptable because no standard convention exists to specify which codes should be returned by programs to indicate errors. Perhaps error codes are universally ignored because they aren’t displayed when a user is typing commands at a shell prompt. Error codes and error checking are so absent from the Unix Canon that many programs don’t even bother to report them in the first place. Date: Tue, 6 Oct 92 08:44:17 PDT From: Bjorn Freeman-Benson bnfb@ursamajor.uvic.ca Subject: It’s always good news in Unix land To: UNIX-HATERS Consider this tar program. Like all Unix “tools” (and I use the word loosely) it works in strange and unique ways. For example, tar is a program with lots of positive energy and thus is convinced that noth- ing bad will ever happen and thus it never returns an error status. In