Index: BOOK/introduction/common/changelog.xml
===================================================================
--- BOOK/introduction/common/changelog.xml	(revision 5d7c3f541427ef6ae363aabcbc8576d1397a48c3)
+++ BOOK/introduction/common/changelog.xml	(revision 973b90d5ce7ab452d06d5d8f8f33bb5c588bfb5e)
@@ -36,4 +36,13 @@
     </listitem>
 -->
+
+    <listitem>
+      <para>March 9, 2009</para>
+      <itemizedlist>
+        <listitem>
+          <para>[Jim] - Updated Bash Branch Update Patch to -3.</para>
+        </listitem>
+      </itemizedlist>
+    </listitem>
 
     <listitem>
Index: BOOK/patches.ent
===================================================================
--- BOOK/patches.ent	(revision 5d7c3f541427ef6ae363aabcbc8576d1397a48c3)
+++ BOOK/patches.ent	(revision 973b90d5ce7ab452d06d5d8f8f33bb5c588bfb5e)
@@ -5,7 +5,7 @@
 <!-- Start of Common Patches -->
 
-<!ENTITY bash-branch_update-patch "bash-&bash-version;-branch_update-2.patch">
-<!ENTITY bash-branch_update-patch-md5 "75986203c47cf97f650a392ecfce4e65">
-<!ENTITY bash-branch_update-patch-size "10 KB">
+<!ENTITY bash-branch_update-patch "bash-&bash-version;-branch_update-3.patch">
+<!ENTITY bash-branch_update-patch-md5 "1121b5d966599721aaf6dffb03f13d8c">
+<!ENTITY bash-branch_update-patch-size "14 KB">
 
 <!ENTITY binutils-branch_update-patch "binutils-&binutils-version;-branch_update-1.patch">
Index: tches/bash-4.0-branch_update-2.patch
===================================================================
--- patches/bash-4.0-branch_update-2.patch	(revision 5d7c3f541427ef6ae363aabcbc8576d1397a48c3)
+++ 	(revision )
@@ -1,379 +1,0 @@
-Submitted By: Jim Gifford (jim at cross-lfs dot org)
-Date: 03-02-2009
-Initial Package Version: 4.0
-Origin: Upstream
-Upstream Status: Applied
-Description: Fixes from the Mailing List - Bash Bug 
-             http://lists.gnu.org/archive/html/bug-bash/2009-02/index.html
-
-diff -Naur bash-4.0.orig/arrayfunc.c bash-4.0/arrayfunc.c
---- bash-4.0.orig/arrayfunc.c	2009-01-04 11:32:21.000000000 -0800
-+++ bash-4.0/arrayfunc.c	2009-03-02 12:37:07.363274758 -0800
-@@ -604,64 +604,7 @@
-     }
- }
- 
--/* This function assumes s[i] == '['; returns with s[ret] == ']' if
--   an array subscript is correctly parsed. */
--int
--skipsubscript (s, i)
--     const char *s;
--     int i;
--{
--  int count, c;
--#if defined (HANDLE_MULTIBYTE)
--  mbstate_t state, state_bak;
--  size_t slength, mblength;
--#endif
--
--#if defined (HANDLE_MULTIBYTE)
--  memset (&state, '\0', sizeof (mbstate_t));
--  slength = strlen (s + i);
--#endif
--  
--  count = 1;
--  while (count)
--    {
--      /* Advance one (possibly multibyte) character in S starting at I. */
--#if defined (HANDLE_MULTIBYTE)
--      if (MB_CUR_MAX > 1)
--	{
--	  state_bak = state;
--	  mblength = mbrlen (s + i, slength, &state);
--
--	  if (MB_INVALIDCH (mblength))
--	    {
--	      state = state_bak;
--	      i++;
--	      slength--;
--	    }
--	  else if (MB_NULLWCH (mblength))
--	    return i;
--	  else
--	    {
--	      i += mblength;
--	      slength -= mblength;
--	    }
--	}
--      else
--#endif
--      ++i;
--
--      c = s[i];
--
--      if (c == 0)
--	break;
--      else if (c == '[')
--	count++;
--      else if (c == ']')
--	count--;
--    }
--
--  return i;
--}
-+/* skipsubscript moved to subst.c to use private functions. 2009/02/24. */
- 
- /* This function is called with SUB pointing to just after the beginning
-    `[' of an array subscript and removes the array element to which SUB
-diff -Naur bash-4.0.orig/builtins/declare.def bash-4.0/builtins/declare.def
---- bash-4.0.orig/builtins/declare.def	2009-01-04 11:32:22.000000000 -0800
-+++ bash-4.0/builtins/declare.def	2009-03-02 12:37:07.363274758 -0800
-@@ -287,6 +287,12 @@
- 	      name[offset - 1] = '\0';
- 	    }
- 	}
-+      else if (legal_identifier (name) == 0)
-+	{
-+	  sh_invalidid (name);
-+	  assign_error++;
-+	  NEXT_VARIABLE ();
-+	}
-       else
- 	value = "";
- 
-@@ -295,6 +301,13 @@
-       subscript_start = (char *)NULL;
-       if (t = strchr (name, '['))	/* ] */
- 	{
-+	  /* If offset != 0 we have already validated any array reference */
-+	  if (offset == 0 && valid_array_reference (name) == 0)
-+	    {
-+	      sh_invalidid (name);
-+	      assign_error++;
-+	      NEXT_VARIABLE ();
-+	    }
- 	  subscript_start = t;
- 	  *t = '\0';
- 	  making_array_special = 1;
-@@ -484,7 +497,7 @@
- 	    }
- 	  /* declare -a name[[n]] or declare name[n] makes name an indexed
- 	     array variable. */
--	  else if ((making_array_special || (flags_on & att_array)) && array_p (var) == 0)
-+	  else if ((making_array_special || (flags_on & att_array)) && array_p (var) == 0 && assoc_p (var) == 0)
- 	    var = convert_var_to_array (var);
- #endif /* ARRAY_VARS */
- 
-diff -Naur bash-4.0.orig/builtins/exit.def bash-4.0/builtins/exit.def
---- bash-4.0.orig/builtins/exit.def	2009-01-04 11:32:22.000000000 -0800
-+++ bash-4.0/builtins/exit.def	2009-03-02 12:37:07.367275038 -0800
-@@ -113,7 +113,7 @@
-       for (i = stopmsg = 0; i < js.j_jobslots; i++)
- 	if (jobs[i] && STOPPED (i))
- 	  stopmsg = JSTOPPED;
--	else if (check_jobs_at_exit && stopmsg == 0 && RUNNING (i))
-+	else if (check_jobs_at_exit && stopmsg == 0 && jobs[i] && RUNNING (i))
- 	  stopmsg = JRUNNING;
- 
-       if (stopmsg == JSTOPPED)
-diff -Naur bash-4.0.orig/builtins/read.def bash-4.0/builtins/read.def
---- bash-4.0.orig/builtins/read.def	2009-01-15 20:11:21.000000000 -0800
-+++ bash-4.0/builtins/read.def	2009-03-02 13:01:12.743891046 -0800
-@@ -369,14 +369,14 @@
-       code = setjmp (alrmbuf);
-       if (code)
- 	{
--#if 0
-+	  /* Tricky.  The top of the unwind-protect stack is the free of
-+	     input_string.  We want to run all the rest and use input_string,
-+	     so we have to remove it from the stack. */
-+	  remove_unwind_protect ();
- 	  run_unwind_frame ("read_builtin");
--	  return (EXECUTION_FAILURE);
--#else
- 	  input_string[i] = '\0';	/* make sure it's terminated */
--	  retval = 128+SIGALRM;;
-+	  retval = 128+SIGALRM;
- 	  goto assign_vars;
--#endif
- 	}
-       old_alrm = set_signal_handler (SIGALRM, sigalrm);
-       add_unwind_protect (reset_alarm, (char *)NULL);
-diff -Naur bash-4.0.orig/parse.y bash-4.0/parse.y
---- bash-4.0.orig/parse.y	2009-01-08 05:29:12.000000000 -0800
-+++ bash-4.0/parse.y	2009-03-02 12:37:07.367275038 -0800
-@@ -1615,10 +1615,11 @@
- {
-   int *ret;
- 
--  ret = (int *)xmalloc (3 * sizeof (int));
-+  ret = (int *)xmalloc (4 * sizeof (int));
-   ret[0] = last_read_token;
-   ret[1] = token_before_that;
-   ret[2] = two_tokens_ago;
-+  ret[3] = current_token;
-   return ret;
- }
- 
-@@ -1631,6 +1632,7 @@
-   last_read_token = ts[0];
-   token_before_that = ts[1];
-   two_tokens_ago = ts[2];
-+  current_token = ts[3];
- }
- 
- /*
-@@ -2668,6 +2670,7 @@
-   FREE (word_desc_to_read);
-   word_desc_to_read = (WORD_DESC *)NULL;
- 
-+  current_token = '\n';		/* XXX */
-   last_read_token = '\n';
-   token_to_read = '\n';
- }
-@@ -2915,6 +2918,7 @@
- #define P_DQUOTE	0x04
- #define P_COMMAND	0x08	/* parsing a command, so look for comments */
- #define P_BACKQUOTE	0x10	/* parsing a backquoted command substitution */
-+#define P_ARRAYSUB	0x20	/* parsing a [...] array subscript for assignment */
- 
- /* Lexical state while parsing a grouping construct or $(...). */
- #define LEX_WASDOL	0x001
-@@ -3129,6 +3133,8 @@
- 	      APPEND_NESTRET ();
- 	      FREE (nestret);
- 	    }
-+	  else if ((flags & P_ARRAYSUB) && (tflags & LEX_WASDOL) && (ch == '(' || ch == '{' || ch == '['))	/* ) } ] */
-+	    goto parse_dollar_word;
- 	}
-       /* Parse an old-style command substitution within double quotes as a
- 	 single word. */
-@@ -3145,6 +3151,7 @@
-       else if MBTEST(open != '`' && (tflags & LEX_WASDOL) && (ch == '(' || ch == '{' || ch == '['))	/* ) } ] */
- 	/* check for $(), $[], or ${} inside quoted string. */
- 	{
-+parse_dollar_word:
- 	  if (open == ch)	/* undo previous increment */
- 	    count--;
- 	  if (ch == '(')		/* ) */
-@@ -3306,7 +3313,7 @@
- 	}
- 
-       /* Meta-characters that can introduce a reserved word.  Not perfect yet. */
--      if MBTEST((tflags & LEX_RESWDOK) == 0 && (tflags & LEX_CKCASE) && (tflags & LEX_INCOMMENT) == 0 && shellmeta(ch))
-+      if MBTEST((tflags & LEX_PASSNEXT) == 0 && (tflags & LEX_RESWDOK) == 0 && (tflags & LEX_CKCASE) && (tflags & LEX_INCOMMENT) == 0 && shellmeta(ch))
- 	{
- 	  /* Add this character. */
- 	  RESIZE_MALLOCED_BUFFER (ret, retind, 1, retsize, 64);
-@@ -3394,8 +3401,11 @@
- 		}
- 	      else
- 		shell_ungetc (peekc);
--	      tflags |= LEX_HEREDELIM;
--	      lex_firstind = -1;
-+	      if (peekc != '<')
-+		{
-+		  tflags |= LEX_HEREDELIM;
-+		  lex_firstind = -1;
-+		}
- 	      continue;
- 	    }
- 	  else
-@@ -4248,7 +4258,7 @@
- 		     ((token_index > 0 && assignment_acceptable (last_read_token) && token_is_ident (token, token_index)) ||
- 		      (token_index == 0 && (parser_state&PST_COMPASSIGN))))
-         {
--	  ttok = parse_matched_pair (cd, '[', ']', &ttoklen, 0);
-+	  ttok = parse_matched_pair (cd, '[', ']', &ttoklen, P_ARRAYSUB);
- 	  if (ttok == &matched_pair_error)
- 	    return -1;		/* Bail immediately. */
- 	  RESIZE_MALLOCED_BUFFER (token, token_index, ttoklen + 2,
-@@ -4449,6 +4459,7 @@
-     case '}':		/* XXX */
-     case AND_AND:
-     case BANG:
-+    case BAR_AND:
-     case DO:
-     case DONE:
-     case ELIF:
-diff -Naur bash-4.0.orig/pcomplete.c bash-4.0/pcomplete.c
---- bash-4.0.orig/pcomplete.c	2009-02-01 14:12:31.000000000 -0800
-+++ bash-4.0/pcomplete.c	2009-03-02 12:37:07.367275038 -0800
-@@ -1032,6 +1032,7 @@
-   cmdlist = build_arg_list (funcname, text, lwords, cw);
- 
-   pps = &ps;
-+  save_parser_state (pps);
-   begin_unwind_frame ("gen-shell-function-matches");
-   add_unwind_protect (restore_parser_state, (char *)pps);
-   add_unwind_protect (dispose_words, (char *)cmdlist);
-diff -Naur bash-4.0.orig/subst.c bash-4.0/subst.c
---- bash-4.0.orig/subst.c	2009-01-28 11:34:12.000000000 -0800
-+++ bash-4.0/subst.c	2009-03-02 12:37:07.371275038 -0800
-@@ -222,6 +222,7 @@
- static int skip_double_quoted __P((char *, size_t, int));
- static char *extract_delimited_string __P((char *, int *, char *, char *, char *, int));
- static char *extract_dollar_brace_string __P((char *, int *, int, int));
-+static int skip_matched_pair __P((const char *, int, int, int, int));
- 
- static char *pos_params __P((char *, int, int, int));
- 
-@@ -1374,6 +1375,107 @@
- 
- #define CQ_RETURN(x) do { no_longjmp_on_fatal_error = 0; return (x); } while (0)
- 
-+/* This function assumes s[i] == open; returns with s[ret] == close; used to
-+   parse array subscripts.  FLAGS currently unused. */
-+static int
-+skip_matched_pair (string, start, open, close, flags)
-+     const char *string;
-+     int start, open, close, flags;
-+{
-+  int i, pass_next, backq, si, c, count;
-+  size_t slen;
-+  char *temp, *ss;
-+  DECLARE_MBSTATE;
-+
-+  slen = strlen (string + start) + start;
-+  no_longjmp_on_fatal_error = 1;
-+
-+  i = start + 1;		/* skip over leading bracket */
-+  count = 1;
-+  pass_next = backq = 0;
-+  ss = (char *)string;
-+  while (c = string[i])
-+    {
-+      if (pass_next)
-+	{
-+	  pass_next = 0;
-+	  if (c == 0)
-+	    CQ_RETURN(i);
-+	  ADVANCE_CHAR (string, slen, i);
-+	  continue;
-+	}
-+      else if (c == '\\')
-+	{
-+	  pass_next = 1;
-+	  i++;
-+	  continue;
-+	}
-+      else if (backq)
-+	{
-+	  if (c == '`')
-+	    backq = 0;
-+	  ADVANCE_CHAR (string, slen, i);
-+	  continue;
-+	}
-+      else if (c == '`')
-+	{
-+	  backq = 1;
-+	  i++;
-+	  continue;
-+	}
-+      else if (c == open)
-+	{
-+	  count++;
-+	  i++;
-+	  continue;
-+	}
-+      else if (c == close)
-+	{
-+	  count--;
-+	  if (count == 0)
-+	    break;
-+	  i++;
-+	  continue;
-+	}
-+      else if (c == '\'' || c == '"')
-+	{
-+	  i = (c == '\'') ? skip_single_quoted (ss, slen, ++i)
-+			  : skip_double_quoted (ss, slen, ++i);
-+	  /* no increment, the skip functions increment past the closing quote. */
-+	}
-+      else if (c == '$' && (string[i+1] == LPAREN || string[i+1] == LBRACE))
-+	{
-+	  si = i + 2;
-+	  if (string[si] == '\0')
-+	    CQ_RETURN(si);
-+
-+	  if (string[i+1] == LPAREN)
-+	    temp = extract_delimited_string (ss, &si, "$(", "(", ")", SX_NOALLOC|SX_COMMAND); /* ) */
-+	  else
-+	    temp = extract_dollar_brace_string (ss, &si, 0, SX_NOALLOC);
-+	  i = si;
-+	  if (string[i] == '\0')	/* don't increment i past EOS in loop */
-+	    break;
-+	  i++;
-+	  continue;
-+	}
-+      else
-+	ADVANCE_CHAR (string, slen, i);
-+    }
-+
-+  CQ_RETURN(i);
-+}
-+
-+#if defined (ARRAY_VARS)
-+int
-+skipsubscript (string, start)
-+     const char *string;
-+     int start;
-+{
-+  return (skip_matched_pair (string, start, '[', ']', 0));
-+}
-+#endif
-+
- /* Skip characters in STRING until we find a character in DELIMS, and return
-    the index of that character.  START is the index into string at which we
-    begin.  This is similar in spirit to strpbrk, but it returns an index into
-
Index: patches/bash-4.0-branch_update-3.patch
===================================================================
--- patches/bash-4.0-branch_update-3.patch	(revision 973b90d5ce7ab452d06d5d8f8f33bb5c588bfb5e)
+++ patches/bash-4.0-branch_update-3.patch	(revision 973b90d5ce7ab452d06d5d8f8f33bb5c588bfb5e)
@@ -0,0 +1,497 @@
+Submitted By: Jim Gifford (jim at cross-lfs dot org)
+Date: 03-09-2009
+Initial Package Version: 4.0
+Origin: Upstream
+Upstream Status: Applied
+Description: Contains all upstream patches up to 4.0-010
+
+diff -Naur bash-4.0.orig/arrayfunc.c bash-4.0/arrayfunc.c
+--- bash-4.0.orig/arrayfunc.c	2009-01-04 11:32:21.000000000 -0800
++++ bash-4.0/arrayfunc.c	2009-03-09 15:07:05.270012850 -0700
+@@ -604,64 +604,7 @@
+     }
+ }
+ 
+-/* This function assumes s[i] == '['; returns with s[ret] == ']' if
+-   an array subscript is correctly parsed. */
+-int
+-skipsubscript (s, i)
+-     const char *s;
+-     int i;
+-{
+-  int count, c;
+-#if defined (HANDLE_MULTIBYTE)
+-  mbstate_t state, state_bak;
+-  size_t slength, mblength;
+-#endif
+-
+-#if defined (HANDLE_MULTIBYTE)
+-  memset (&state, '\0', sizeof (mbstate_t));
+-  slength = strlen (s + i);
+-#endif
+-  
+-  count = 1;
+-  while (count)
+-    {
+-      /* Advance one (possibly multibyte) character in S starting at I. */
+-#if defined (HANDLE_MULTIBYTE)
+-      if (MB_CUR_MAX > 1)
+-	{
+-	  state_bak = state;
+-	  mblength = mbrlen (s + i, slength, &state);
+-
+-	  if (MB_INVALIDCH (mblength))
+-	    {
+-	      state = state_bak;
+-	      i++;
+-	      slength--;
+-	    }
+-	  else if (MB_NULLWCH (mblength))
+-	    return i;
+-	  else
+-	    {
+-	      i += mblength;
+-	      slength -= mblength;
+-	    }
+-	}
+-      else
+-#endif
+-      ++i;
+-
+-      c = s[i];
+-
+-      if (c == 0)
+-	break;
+-      else if (c == '[')
+-	count++;
+-      else if (c == ']')
+-	count--;
+-    }
+-
+-  return i;
+-}
++/* skipsubscript moved to subst.c to use private functions. 2009/02/24. */
+ 
+ /* This function is called with SUB pointing to just after the beginning
+    `[' of an array subscript and removes the array element to which SUB
+diff -Naur bash-4.0.orig/builtins/declare.def bash-4.0/builtins/declare.def
+--- bash-4.0.orig/builtins/declare.def	2009-01-04 11:32:22.000000000 -0800
++++ bash-4.0/builtins/declare.def	2009-03-09 15:07:02.561839362 -0700
+@@ -295,6 +295,13 @@
+       subscript_start = (char *)NULL;
+       if (t = strchr (name, '['))	/* ] */
+ 	{
++	  /* If offset != 0 we have already validated any array reference */
++	  if (offset == 0 && valid_array_reference (name) == 0)
++	    {
++	      sh_invalidid (name);
++	      assign_error++;
++	      NEXT_VARIABLE ();
++	    }
+ 	  subscript_start = t;
+ 	  *t = '\0';
+ 	  making_array_special = 1;
+@@ -484,7 +491,7 @@
+ 	    }
+ 	  /* declare -a name[[n]] or declare name[n] makes name an indexed
+ 	     array variable. */
+-	  else if ((making_array_special || (flags_on & att_array)) && array_p (var) == 0)
++	  else if ((making_array_special || (flags_on & att_array)) && array_p (var) == 0 && assoc_p (var) == 0)
+ 	    var = convert_var_to_array (var);
+ #endif /* ARRAY_VARS */
+ 
+diff -Naur bash-4.0.orig/builtins/exit.def bash-4.0/builtins/exit.def
+--- bash-4.0.orig/builtins/exit.def	2009-01-04 11:32:22.000000000 -0800
++++ bash-4.0/builtins/exit.def	2009-03-09 15:07:01.245754993 -0700
+@@ -113,7 +113,7 @@
+       for (i = stopmsg = 0; i < js.j_jobslots; i++)
+ 	if (jobs[i] && STOPPED (i))
+ 	  stopmsg = JSTOPPED;
+-	else if (check_jobs_at_exit && stopmsg == 0 && RUNNING (i))
++	else if (check_jobs_at_exit && stopmsg == 0 && jobs[i] && RUNNING (i))
+ 	  stopmsg = JRUNNING;
+ 
+       if (stopmsg == JSTOPPED)
+diff -Naur bash-4.0.orig/builtins/read.def bash-4.0/builtins/read.def
+--- bash-4.0.orig/builtins/read.def	2009-01-15 20:11:21.000000000 -0800
++++ bash-4.0/builtins/read.def	2009-03-09 15:07:07.890180751 -0700
+@@ -369,14 +369,14 @@
+       code = setjmp (alrmbuf);
+       if (code)
+ 	{
+-#if 0
++	  /* Tricky.  The top of the unwind-protect stack is the free of
++	     input_string.  We want to run all the rest and use input_string,
++	     so we have to remove it from the stack. */
++	  remove_unwind_protect ();
+ 	  run_unwind_frame ("read_builtin");
+-	  return (EXECUTION_FAILURE);
+-#else
+ 	  input_string[i] = '\0';	/* make sure it's terminated */
+-	  retval = 128+SIGALRM;;
++	  retval = 128+SIGALRM;
+ 	  goto assign_vars;
+-#endif
+ 	}
+       old_alrm = set_signal_handler (SIGALRM, sigalrm);
+       add_unwind_protect (reset_alarm, (char *)NULL);
+diff -Naur bash-4.0.orig/parse.y bash-4.0/parse.y
+--- bash-4.0.orig/parse.y	2009-01-08 05:29:12.000000000 -0800
++++ bash-4.0/parse.y	2009-03-09 15:07:09.194264282 -0700
+@@ -1615,10 +1615,11 @@
+ {
+   int *ret;
+ 
+-  ret = (int *)xmalloc (3 * sizeof (int));
++  ret = (int *)xmalloc (4 * sizeof (int));
+   ret[0] = last_read_token;
+   ret[1] = token_before_that;
+   ret[2] = two_tokens_ago;
++  ret[3] = current_token;
+   return ret;
+ }
+ 
+@@ -1631,6 +1632,7 @@
+   last_read_token = ts[0];
+   token_before_that = ts[1];
+   two_tokens_ago = ts[2];
++  current_token = ts[3];
+ }
+ 
+ /*
+@@ -2668,6 +2670,7 @@
+   FREE (word_desc_to_read);
+   word_desc_to_read = (WORD_DESC *)NULL;
+ 
++  current_token = '\n';		/* XXX */
+   last_read_token = '\n';
+   token_to_read = '\n';
+ }
+@@ -2915,6 +2918,7 @@
+ #define P_DQUOTE	0x04
+ #define P_COMMAND	0x08	/* parsing a command, so look for comments */
+ #define P_BACKQUOTE	0x10	/* parsing a backquoted command substitution */
++#define P_ARRAYSUB	0x20	/* parsing a [...] array subscript for assignment */
+ 
+ /* Lexical state while parsing a grouping construct or $(...). */
+ #define LEX_WASDOL	0x001
+@@ -2927,6 +2931,7 @@
+ #define LEX_INHEREDOC	0x080
+ #define LEX_HEREDELIM	0x100		/* reading here-doc delimiter */
+ #define LEX_STRIPDOC	0x200		/* <<- strip tabs from here doc delim */
++#define LEX_INWORD	0x400
+ 
+ #define COMSUB_META(ch)		((ch) == ';' || (ch) == '&' || (ch) == '|')
+ 
+@@ -3129,6 +3134,8 @@
+ 	      APPEND_NESTRET ();
+ 	      FREE (nestret);
+ 	    }
++	  else if ((flags & P_ARRAYSUB) && (tflags & LEX_WASDOL) && (ch == '(' || ch == '{' || ch == '['))	/* ) } ] */
++	    goto parse_dollar_word;
+ 	}
+       /* Parse an old-style command substitution within double quotes as a
+ 	 single word. */
+@@ -3145,6 +3152,7 @@
+       else if MBTEST(open != '`' && (tflags & LEX_WASDOL) && (ch == '(' || ch == '{' || ch == '['))	/* ) } ] */
+ 	/* check for $(), $[], or ${} inside quoted string. */
+ 	{
++parse_dollar_word:
+ 	  if (open == ch)	/* undo previous increment */
+ 	    count--;
+ 	  if (ch == '(')		/* ) */
+@@ -3179,7 +3187,7 @@
+      int open, close;
+      int *lenp, flags;
+ {
+-  int count, ch, peekc, tflags, lex_rwlen, lex_firstind;
++  int count, ch, peekc, tflags, lex_rwlen, lex_wlen, lex_firstind;
+   int nestlen, ttranslen, start_lineno;
+   char *ret, *nestret, *ttrans, *heredelim;
+   int retind, retsize, rflags, hdlen;
+@@ -3200,7 +3208,7 @@
+   retind = 0;
+ 
+   start_lineno = line_number;
+-  lex_rwlen = 0;
++  lex_rwlen = lex_wlen = 0;
+ 
+   heredelim = 0;
+   lex_firstind = -1;
+@@ -3267,6 +3275,46 @@
+ 	  continue;
+ 	}
+ 
++      if (tflags & LEX_PASSNEXT)		/* last char was backslash */
++	{
++/*itrace("parse_comsub:%d: lex_passnext -> 0 ch = `%c' (%d)", line_number, ch, __LINE__);*/
++	  tflags &= ~LEX_PASSNEXT;
++	  if (qc != '\'' && ch == '\n')	/* double-quoted \<newline> disappears. */
++	    {
++	      if (retind > 0)
++		retind--;	/* swallow previously-added backslash */
++	      continue;
++	    }
++
++	  RESIZE_MALLOCED_BUFFER (ret, retind, 2, retsize, 64);
++	  if MBTEST(ch == CTLESC || ch == CTLNUL)
++	    ret[retind++] = CTLESC;
++	  ret[retind++] = ch;
++	  continue;
++	}
++
++      /* If this is a shell break character, we are not in a word.  If not,
++	 we either start or continue a word. */
++      if MBTEST(shellbreak (ch))
++	{
++	  tflags &= ~LEX_INWORD;
++/*itrace("parse_comsub:%d: lex_inword -> 0 ch = `%c' (%d)", line_number, ch, __LINE__);*/
++	}
++      else
++	{
++	  if (tflags & LEX_INWORD)
++	    {
++	      lex_wlen++;
++/*itrace("parse_comsub:%d: lex_inword == 1 ch = `%c' lex_wlen = %d (%d)", line_number, ch, lex_wlen, __LINE__);*/
++	    }	      
++	  else
++	    {
++/*itrace("parse_comsub:%d: lex_inword -> 1 ch = `%c' (%d)", line_number, ch, __LINE__);*/
++	      tflags |= LEX_INWORD;
++	      lex_wlen = 0;
++	    }
++	}
++
+       /* Skip whitespace */
+       if MBTEST(shellblank (ch) && lex_rwlen == 0)
+         {
+@@ -3364,9 +3412,21 @@
+ }	        
+ 	      tflags &= ~LEX_RESWDOK;
+ 	    }
+-	  else if (shellbreak (ch) == 0)
++	  else if MBTEST((tflags & LEX_CKCOMMENT) && ch == '#' && (lex_rwlen == 0 || ((tflags & LEX_INWORD) && lex_wlen == 0)))
++	    ;	/* don't modify LEX_RESWDOK if we're starting a comment */
++	  else if MBTEST((tflags & LEX_INCASE) && ch != '\n')
++	    /* If we can read a reserved word and we're in case, we're at the
++	       point where we can read a new pattern list or an esac.  We
++	       handle the esac case above.  If we read a newline, we want to
++	       leave LEX_RESWDOK alone.  If we read anything else, we want to
++	       turn off LEX_RESWDOK, since we're going to read a pattern list. */
+ {
+-	      tflags &= ~LEX_RESWDOK;
++	    tflags &= ~LEX_RESWDOK;
++/*itrace("parse_comsub:%d: lex_incase == 1 found `%c', lex_reswordok -> 0", line_number, ch);*/
++}
++	  else if MBTEST(shellbreak (ch) == 0)
++{
++	    tflags &= ~LEX_RESWDOK;
+ /*itrace("parse_comsub:%d: found `%c', lex_reswordok -> 0", line_number, ch);*/
+ }
+ 	}
+@@ -3394,36 +3454,23 @@
+ 		}
+ 	      else
+ 		shell_ungetc (peekc);
+-	      tflags |= LEX_HEREDELIM;
+-	      lex_firstind = -1;
++	      if (peekc != '<')
++		{
++		  tflags |= LEX_HEREDELIM;
++		  lex_firstind = -1;
++		}
+ 	      continue;
+ 	    }
+ 	  else
+-	    ch = peekc;		/* fall through and continue XXX - this skips comments if peekc == '#' */
++	    ch = peekc;		/* fall through and continue XXX */
+ 	}
+-      /* Not exactly right yet, should handle shell metacharacters, too.  If
+-	 any changes are made to this test, make analogous changes to subst.c:
+-	 extract_delimited_string(). */
+-      else if MBTEST((tflags & LEX_CKCOMMENT) && (tflags & LEX_INCOMMENT) == 0 && ch == '#' && (retind == 0 || ret[retind-1] == '\n' || shellblank (ret[retind - 1])))
++      else if MBTEST((tflags & LEX_CKCOMMENT) && (tflags & LEX_INCOMMENT) == 0 && ch == '#' && (((tflags & LEX_RESWDOK) && lex_rwlen == 0) || ((tflags & LEX_INWORD) && lex_wlen == 0)))
++{
++/*itrace("parse_comsub:%d: lex_incomment -> 1 (%d)", line_number, __LINE__);*/
+ 	tflags |= LEX_INCOMMENT;
++}
+ 
+-      if (tflags & LEX_PASSNEXT)		/* last char was backslash */
+-	{
+-	  tflags &= ~LEX_PASSNEXT;
+-	  if (qc != '\'' && ch == '\n')	/* double-quoted \<newline> disappears. */
+-	    {
+-	      if (retind > 0)
+-		retind--;	/* swallow previously-added backslash */
+-	      continue;
+-	    }
+-
+-	  RESIZE_MALLOCED_BUFFER (ret, retind, 2, retsize, 64);
+-	  if MBTEST(ch == CTLESC || ch == CTLNUL)
+-	    ret[retind++] = CTLESC;
+-	  ret[retind++] = ch;
+-	  continue;
+-	}
+-      else if MBTEST(ch == CTLESC || ch == CTLNUL)	/* special shell escapes */
++      if MBTEST(ch == CTLESC || ch == CTLNUL)	/* special shell escapes */
+ 	{
+ 	  RESIZE_MALLOCED_BUFFER (ret, retind, 2, retsize, 64);
+ 	  ret[retind++] = CTLESC;
+@@ -4248,7 +4295,7 @@
+ 		     ((token_index > 0 && assignment_acceptable (last_read_token) && token_is_ident (token, token_index)) ||
+ 		      (token_index == 0 && (parser_state&PST_COMPASSIGN))))
+         {
+-	  ttok = parse_matched_pair (cd, '[', ']', &ttoklen, 0);
++	  ttok = parse_matched_pair (cd, '[', ']', &ttoklen, P_ARRAYSUB);
+ 	  if (ttok == &matched_pair_error)
+ 	    return -1;		/* Bail immediately. */
+ 	  RESIZE_MALLOCED_BUFFER (token, token_index, ttoklen + 2,
+@@ -4449,6 +4496,7 @@
+     case '}':		/* XXX */
+     case AND_AND:
+     case BANG:
++    case BAR_AND:
+     case DO:
+     case DONE:
+     case ELIF:
+diff -Naur bash-4.0.orig/patchlevel.h bash-4.0/patchlevel.h
+--- bash-4.0.orig/patchlevel.h	2009-01-04 11:32:40.000000000 -0800
++++ bash-4.0/patchlevel.h	2009-03-09 15:07:09.194264282 -0700
+@@ -25,6 +25,6 @@
+    regexp `^#define[ 	]*PATCHLEVEL', since that's what support/mkversion.sh
+    looks for to find the patch level (for the sccs version string). */
+ 
+-#define PATCHLEVEL 0
++#define PATCHLEVEL 10
+ 
+ #endif /* _PATCHLEVEL_H_ */
+diff -Naur bash-4.0.orig/pcomplete.c bash-4.0/pcomplete.c
+--- bash-4.0.orig/pcomplete.c	2009-02-01 14:12:31.000000000 -0800
++++ bash-4.0/pcomplete.c	2009-03-09 15:06:58.589584858 -0700
+@@ -1032,6 +1032,7 @@
+   cmdlist = build_arg_list (funcname, text, lwords, cw);
+ 
+   pps = &ps;
++  save_parser_state (pps);
+   begin_unwind_frame ("gen-shell-function-matches");
+   add_unwind_protect (restore_parser_state, (char *)pps);
+   add_unwind_protect (dispose_words, (char *)cmdlist);
+diff -Naur bash-4.0.orig/subst.c bash-4.0/subst.c
+--- bash-4.0.orig/subst.c	2009-01-28 11:34:12.000000000 -0800
++++ bash-4.0/subst.c	2009-03-09 15:07:05.274015365 -0700
+@@ -222,6 +222,7 @@
+ static int skip_double_quoted __P((char *, size_t, int));
+ static char *extract_delimited_string __P((char *, int *, char *, char *, char *, int));
+ static char *extract_dollar_brace_string __P((char *, int *, int, int));
++static int skip_matched_pair __P((const char *, int, int, int, int));
+ 
+ static char *pos_params __P((char *, int, int, int));
+ 
+@@ -1374,6 +1375,107 @@
+ 
+ #define CQ_RETURN(x) do { no_longjmp_on_fatal_error = 0; return (x); } while (0)
+ 
++/* This function assumes s[i] == open; returns with s[ret] == close; used to
++   parse array subscripts.  FLAGS currently unused. */
++static int
++skip_matched_pair (string, start, open, close, flags)
++     const char *string;
++     int start, open, close, flags;
++{
++  int i, pass_next, backq, si, c, count;
++  size_t slen;
++  char *temp, *ss;
++  DECLARE_MBSTATE;
++
++  slen = strlen (string + start) + start;
++  no_longjmp_on_fatal_error = 1;
++
++  i = start + 1;		/* skip over leading bracket */
++  count = 1;
++  pass_next = backq = 0;
++  ss = (char *)string;
++  while (c = string[i])
++    {
++      if (pass_next)
++	{
++	  pass_next = 0;
++	  if (c == 0)
++	    CQ_RETURN(i);
++	  ADVANCE_CHAR (string, slen, i);
++	  continue;
++	}
++      else if (c == '\\')
++	{
++	  pass_next = 1;
++	  i++;
++	  continue;
++	}
++      else if (backq)
++	{
++	  if (c == '`')
++	    backq = 0;
++	  ADVANCE_CHAR (string, slen, i);
++	  continue;
++	}
++      else if (c == '`')
++	{
++	  backq = 1;
++	  i++;
++	  continue;
++	}
++      else if (c == open)
++	{
++	  count++;
++	  i++;
++	  continue;
++	}
++      else if (c == close)
++	{
++	  count--;
++	  if (count == 0)
++	    break;
++	  i++;
++	  continue;
++	}
++      else if (c == '\'' || c == '"')
++	{
++	  i = (c == '\'') ? skip_single_quoted (ss, slen, ++i)
++			  : skip_double_quoted (ss, slen, ++i);
++	  /* no increment, the skip functions increment past the closing quote. */
++	}
++      else if (c == '$' && (string[i+1] == LPAREN || string[i+1] == LBRACE))
++	{
++	  si = i + 2;
++	  if (string[si] == '\0')
++	    CQ_RETURN(si);
++
++	  if (string[i+1] == LPAREN)
++	    temp = extract_delimited_string (ss, &si, "$(", "(", ")", SX_NOALLOC|SX_COMMAND); /* ) */
++	  else
++	    temp = extract_dollar_brace_string (ss, &si, 0, SX_NOALLOC);
++	  i = si;
++	  if (string[i] == '\0')	/* don't increment i past EOS in loop */
++	    break;
++	  i++;
++	  continue;
++	}
++      else
++	ADVANCE_CHAR (string, slen, i);
++    }
++
++  CQ_RETURN(i);
++}
++
++#if defined (ARRAY_VARS)
++int
++skipsubscript (string, start)
++     const char *string;
++     int start;
++{
++  return (skip_matched_pair (string, start, '[', ']', 0));
++}
++#endif
++
+ /* Skip characters in STRING until we find a character in DELIMS, and return
+    the index of that character.  START is the index into string at which we
+    begin.  This is similar in spirit to strpbrk, but it returns an index into
