automake-patches
[Top][All Lists]
Advanced

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

Description of ksh bug w.r.t. `${1+"$@"}'


From: Stefano Lattarini
Subject: Description of ksh bug w.r.t. `${1+"$@"}'
Date: Sun, 13 Dec 2009 18:44:39 +0100
User-agent: KMail/1.12.1 (Linux/2.6.30-2-686; KDE/4.3.2; i686; ; )

The AT&T version of the Korn shell has a strange bug regarding
the expression `${1+"$@"}'; more precisely, when exactly one empty
argument is passed to a shell function, inside that function the
expression `${1+"$@"}' will expand to nothing (not to a single empty
string, as one would expect), even if `$#' is correctly recognized
to be `1'.

Here is a simple example showing the bug.

  $ cat foo.sh
  foo() {
      echo "\$#: $#"
      for i in ${1+"$@"}; do
          printf "x${i}y "
      done
      echo
  }
  echo ---
  foo
  echo ---
  foo ""
  echo ---
  foo "" ""
  echo ---
  foo "" a
  echo ---
  foo a "" b
  echo ---
  
  $ sh foo.sh  # sh can be bash, pdksh, dash, heirloom-sh
  ---
  $#: 0
  
  ---
  $#: 1
  xy
  ---
  $#: 2
  xy xy
  ---
  $#: 2
  xy xay
  ---
  $#: 3
  xay xy xby
  ---
  
  $ ksh foo.sh # AT&T Korn shell
  ---
  $#: 0
  
  ---
  $#: 1
  
  ---
  $#: 2
  xy
  ---
  $#: 2
  xy xay
  ---
  $#: 3
  xay xy xby
  ---

More details about the Ksh version used:

  $ dpkg -l ksh
  ||/ Name     Version    Description
  +++-========-==========-========================================
  ii  ksh      93t+-2     The real, AT&T version of the Korn shell

  $ ksh -c 'echo "$KSH_VERSION"; echo "${.sh.version}"'
  Version JM 93t+ 2009-05-01
  Version JM 93t+ 2009-05-01




reply via email to

[Prev in Thread] Current Thread [Next in Thread]