bug-bash
[Top][All Lists]
Advanced

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

${@:0:n} includes one parameter too few


From: neil
Subject: ${@:0:n} includes one parameter too few
Date: Fri, 09 Oct 2009 23:47:02 -0400

Configuration Information [Automatically generated, do not change]:
Machine: i686
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='i686' 
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i686-pc-linux-gnu' 
-DCONF_VENDOR='pc' -DLOCALEDIR='/usr/local/share/locale' -DPACKAGE='bash' 
-DSHELL -DHAVE_CONFIG_H   -I.  -I. -I./include -I./lib   -g -O2
uname output: Linux dirac.s-z.org 2.6.26-1-openvz-686 #1 SMP Wed Sep 10 
19:04:44 UTC 2008 i686 GNU/Linux
Machine Type: i686-pc-linux-gnu

Bash Version: 4.0
Patch Level: 33
Release Status: release

[apologies if this is a duplicate; the first copy may have been sent with
 a bad From: address]

Description:
        "${@:0:n}" should expand to $0 followed by n-1 positional parameters,
        but actually expands to $0 followed by n-2 positional parameters,
        for a total of only n-1 words.  This is different from ksh's
        behaviour, and seems unintentional and inconsistent.

Repeat-By:
        $ set -- a b c d
        $ echo "${@:0:3}"    # prints "bash a", should be "bash a b"

Fix:
        Apply the following patch.  The effect of the patch is mostly on
        the following loop (params && i < end), which without the patch
        runs one time too few.

diff -ur bash-4.0/subst.c bash-4.0-fixed/subst.c
--- ../bash-4.0/subst.c    2009-07-22 19:15:52.472737094 -0400
+++ subst.c      2009-07-22 19:13:48.316733546 -0400
@@ -2739,7 +2739,7 @@
       save = params = t;
     }
 
-  for (i = 1; params && i < start; i++)
+  for (i = start ? 1 : 0; params && i < start; i++)
     params = params->next;
   if (params == 0)
     return ((char *)NULL);




reply via email to

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