[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Tightening up specification of /bin/sh



Currently the only requirements on the shell interpreter /bin/sh are
that it should adhere to the relevant POSIX standard, and that "echo
-n" should not produce a newline.  Unfortunately, POSIX leaves a large
number of shell features unspecified.  In most of these cases there is
general agreement among shell implementations as to what the behavior
should be, and scripts therefore come to rely on those behaviors.
Policy does not prevent any given /bin/sh from changing these, but
massive breakage can result if they are changed.

I'd like to tighten this up a bit by requiring that /bin/sh adhere to
the consensus of implementations, where POSIX leaves things
unspecified.  What follows is one possible revision.  The wording
isn't ideal; I'm open to suggestions.

zw

*** policy.sgml-3.5.4.0	Fri May  4 00:18:15 2001
--- policy.sgml	Fri May  4 00:41:13 2001
***************
*** 5332,5368 ****
  	  command.</p>
  
  	<p>
! 	  The standard shell interpreter `<tt>/bin/sh</tt>' can be a
! 	  symbolic link to any POSIX compatible shell, if <tt>echo
! 	    -n</tt> does not generate a newline.
  	  <footnote>
  	    <p>
! 	      Debian policy specifies POSIX behavior for /bin/sh, but
! 	      echo -n has widespread use in the Linux community
! 	      (including especially debian policy, the linux kernel
! 	      source, many debian scripts, etc.).  This echo -n
! 	      mechanism is valid but not required under POSIX, hence
! 	      this explicit addition. Also, rumour has it that this
! 	      shall be mandated under the LSB anyway.
  	    </p>
  	  </footnote>
! 	  Thus, shell scripts
! 	  specifying `<tt>/bin/sh</tt>' as interpreter should only
! 	  use POSIX features. If a script requires non-POSIX
! 	  features from the shell interpreter, the appropriate shell
! 	  must be specified in the first line of the script (e.g.,
  	  `<tt>#!/bin/bash</tt>') and the package must depend on the
  	  package providing the shell (unless the shell package is
! 	  marked `Essential', e.g., in the case of
! 	  <prgn>bash</prgn>).
! 	</p>
  
  	<p>
! 	  You may wish to restrict your script to POSIX features when possible so
! 	  that it may use <tt>/bin/sh</tt> as its interpreter. If
! 	  your script works with <prgn>ash</prgn>, it's probably
! 	  POSIX compliant, but if you are in doubt, use
! 	  <tt>/bin/bash</tt>.</p>
  
  	<p>
  	  Perl scripts should check for errors when making any
--- 5332,5394 ----
  	  command.</p>
  
  	<p>
! 	  The standard shell interpreter `<tt>/bin/sh</tt>' is a
! 	  symbolic link to a POSIX compatible shell.  Since the POSIX
! 	  standard for shells leaves important areas unspecified,
! 	  wherever it is lacking, `<tt>/bin/sh</tt>' shall follow the
! 	  <em>consensus behavior</em> of other shell interpreters.
! 	  Consensus behavior is determined by testing at least five
! 	  shell interpreters which claim to be POSIX compatible.  If
! 	  most of them do the same thing, `<tt>/bin/sh</tt>' must
! 	  behave that way.  Otherwise, `<tt>/bin/sh</tt>' should
! 	  pick the most sensible of the observed behaviors, in the
! 	  judgement of its maintainer.
  	  <footnote>
  	    <p>
! 	      Examples of behavior which is determined by consensus
! 	      include the effect of <tt>echo -n</tt>, and the initial
! 	      value of the <tt>IFS</tt> variable.
! 
! 	    <p>
! 	      In Debian, suitable shells for this test include
! 	      <tt>pdksh</tt>, <tt>ash</tt>, and <tt>bash</tt>.  The
! 	      shells shipped as <tt>/bin/sh</tt> by the various BSD
! 	      distributions are also suitable (these are not the same
! 	      as <tt>ash</tt>, despite its package description).
! 	      Various shells shipped with proprietary UNIXes, in
! 	      particular the genuine AT&T <tt>ksh</tt>, are also
! 	      useful to test.
! 
! 	    <p>
! 	      Care should be taken to ensure that one does not test
! 	      the same implementation under multiple guises.
  	    </p>
  	  </footnote>
! 	  <tt>echo -n</tt> is explicitly required to print the
! 	  remainder of its arguments, but no newline.  (Many, but not
! 	  most, of POSIX shells do this.)
! 
! 	<p>
! 	  Shell scripts which specify `<tt>/bin/sh</tt>' as their
! 	  interpreter should only use features specified by POSIX.
! 	  Where POSIX leaves behavior unspecified, they may rely on
! 	  behavior determined by consensus.  If there is no consensus,
! 	  scripts may not rely on the behavior.
! 
! 	<p>
! 	  If a script requires non-POSIX features from the shell
! 	  interpreter, it must name the appropriate shell explicitly
! 	  in the first line of the script (e.g.,
  	  `<tt>#!/bin/bash</tt>') and the package must depend on the
  	  package providing the shell (unless the shell package is
! 	  marked `Essential', as <prgn>bash</prgn> is).
  
  	<p>
! 	  You are encouraged to restrict your script to POSIX features
! 	  and consensus behavior, whenever possible, so that it may
! 	  use <tt>/bin/sh</tt> as its interpreter. If your script
! 	  works with <prgn>ash</prgn>, it's probably POSIX compliant,
! 	  but if you are in doubt, use <tt>/bin/bash</tt>.</p>
  
  	<p>
  	  Perl scripts should check for errors when making any



Reply to: