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

Re: PW#5-1: Bash vs Bourne shell



On Wed, Jan 14, 1998 at 02:50:39PM +0100, Christian Schwarz wrote:
> On Wed, 14 Jan 1998 jdassen@wi.leidenuniv.nl wrote:
> 
> > On Tue, Jan 13, 1998 at 11:34:21PM +0100, Christian Schwarz wrote:
> > >      Restrict your script to POSIX features when possible so that it may
> > >      use /bin/sh as its interpreter. If your script works with ash, it's
> > >      probably POSIX compliant, but if you are in doubt, use /bin/bash.
> > 
> > I'd prefer it if the most often used non-POSIX features of bash could be
> > listed in an appendix, making it easier for maintainers to know which
> > constructs to avoid.
> 
> Certainly. If someone provides me such an appendix, I'll include it in the
> policy manual (if it's short) or we'll make up an extra document for it.
> AFAIR, Adrian offered to write such a manual some time ago. Adrian, are
> you still intrested in doing this?

Yep - this is basically just a list of stuff which I think should go in.
This isn't intended to be the final format, things I'm not sure about have
a "!" at the beginning of the line.

Am I correct in thinking in thinking that bash, ash and pdksh all implement
the POSIX standard (although maybe not by default) - it looks that way from
the man-pages, but I havn't any experience at quite how complient they are.

BASIC
-----
 #brace expansion
 cp {foo,bar}.txt        ->      cp foo.txt bar.txt

 #functions
 function f() { ...}     ->      f() { ...}
 NB: You must have a space immediately after the open brace, you can put
 more spaces (practically) anywhere if needed to improve readability.
 Function names can only contain letters, digits and underscores and cannot
 start with a digit.

 #command substitution (output of a command)
 `command`               ->      $(command)
 NB: in the old style backslash retains its literal meaning unless followed
 by $,` or \, in the new style no characters are treated specially.
 To nest in the old style inner backquotes needed to be quoted with
 backslashes, you can nest the new style as is.

 #redirecting stdout and stderr
 >& word                 ->      > word 2>&1
 &> word                 ->      > word 2>&1 
!filename expansion is not performed on word unless the shell is interactive


 #piping stdout and stderr
 |&                      ->      2>&1 |

 #arithmetic expansion
! $[foo]                  ->      $((foo))

 #foo=$<$bar>
! eval foo=$"$bar"        ->      eval foo=\$${bar}  (foo=${!bar} in bash2)

!Do not use the variables UID, EUID, HOSTTYPE, OSTYPE, MACHTYPE, HOSTNAME

 Do not use nonstandard flags on builtins including "read -r", or any flag
 on "type".


 ADVANCED
 --------
 reserved words may not be aliased


 BASH 2.0
 --------
 Some scripts which ran with bash 1.14 may break with bash 2.x this is
 because the parser was tightened up.

 In a group command, the list must be terminated by a newline or a semicolon
 like this:
 if [ -e foo ]; then { echo foo; echo bar; }; fi
 if [ -e foo ]; then { echo foo; echo bar
                                         }; fi

 PARAMETERS
 ----------
 It looks like these are fine (in ash,bash,pdksh):
    ${parm:-word}            if $parm is null, return word, else return $parm
    ${parm:=word}            assign word to $parm and return it
    ${parm:?word}            print word on stderr if $parm is null
    ${parm:+word}            if $parm is set, return word
    ${#parm}                 length of $parm (parm maybe * or @)
    ${parm#glob}             return $parm with shortest prefix removed
    ${parm##glob}            return $parm with longest prefix removed
    ${parm%glob}             return $parm with shortest suffix removed
    ${parm%%glob}            return $parm with longest suffix removed
 But not these (only in bash):
!    ${parm:len[:offset]}     substring
!    ${parm/pat[/str]}        pattern substitution (once)
!    ${parm//pat[/str]}       pattern substitution (all)

 MISC
 ----
! Don't use "cat << ''" as it is anbiguous, bash and pdksh read until they
! reach a blank line (havn't checked ash).


Comments are most welcome!

Adrian
 
email: adrian.bridgett@poboxes.com       | Debian Linux - www.debian.org
http://www.poboxes.com/adrian.bridgett   | Because bloated, unstable 
PGP key available on public key servers  | operating systems are from MS


Reply to: