<- Page 2: /usr/dt/bin/Xsession

This one is short and amusing:

   1 #!/usr/bin/sh
   2 # @(#) $Revision: 72.2 $
   4 # This is the execable version of read implemented using the
   5 # posix shell built-in read command.
   7 read $@
   8 exit $?

There are two lines of actual code (not counting the shebang and comments), and both of them are wrong. A WrapperScript should use "$@" (never $@) if you're confident that your shell can handle empty arguments properly (which is a fine assumption here, as this is a commercial vendor's script, and they should be confident of their own shell), or ${1+"$@"} if you are not confident (i.e. you are writing a script to be portable to many systems).

Using $@ causes any arguments containing spaces or shell metacharacters, and any empty arguments, to break. There's no reason to use it except ignorance. Adding two bytes to the script would fix that.

The exit $? line is completely unnecessary. The shell already exits with the status from the last command executed. The explicit exit $? adds nothing. It simply reinforces the fact that the author of this script did not know how to write scripts.

Now, you might also wonder what the purpose of this script is. As far as I can tell, it is required to be present by some part of the POSIX standard (this part) so that other programs can call execlp("read", ...);. It is probably never used in real life.

<- Page 2: /usr/dt/bin/Xsession

ShellHallOfShame/Page3 (last edited 2015-02-26 18:29:18 by chomsky)