Differences between revisions 1 and 2
Revision 1 as of 2015-01-28 22:09:56
Size: 1534
Editor: GreyCat
Comment: /usr/bin/read from HP-UX 10.20
Revision 2 as of 2015-02-26 18:29:18
Size: 1634
Editor: chomsky
Comment: add link to the part of the POSIX standard about executing regular built-in utilities
Deletions are marked like this. Additions are marked like this.
Line 22: Line 22:
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 so that other programs can call `execlp("read", ...);`. It is probably never used in real life. 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 ([[http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap01.html#tagtcjh_18|this part]]) so that other programs can call `execlp("read", ...);`. It is probably never used in real life.

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

This one is short and amusing:

   1 #!/usr/bin/sh
   2 # @(#) $Revision: 72.2 $
   3 
   4 # This is the execable version of read implemented using the
   5 # posix shell built-in read command.
   6 
   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)