]> git.ipfire.org Git - thirdparty/bash.git/commitdiff
commit bash-20141003 snapshot
authorChet Ramey <chet.ramey@case.edu>
Fri, 10 Oct 2014 00:25:14 +0000 (20:25 -0400)
committerChet Ramey <chet.ramey@case.edu>
Fri, 10 Oct 2014 00:25:14 +0000 (20:25 -0400)
30 files changed:
CWRU/CWRU.chlog
CWRU/CWRU.chlog~
MANIFEST
MANIFEST~ [new file with mode: 0644]
builtins/evalstring.c
builtins/setattr.def
builtins/setattr.def~ [new file with mode: 0644]
examples/loadables/finfo.c
general.c
general.c~
general.h
general.h~
jobs.c
parse.y
patchlevel.h
print_cmd.c
print_cmd.c~ [new file with mode: 0644]
shell.c~ [new file with mode: 0644]
shell.h
tests/exportfunc.right [new file with mode: 0644]
tests/exportfunc.tests [new file with mode: 0644]
tests/exportfunc.tests~ [new file with mode: 0644]
tests/exportfunc1.sub [new file with mode: 0644]
tests/exportfunc2.sub [new file with mode: 0644]
tests/exportfunc3.sub [new file with mode: 0644]
tests/run-exportfunc [new file with mode: 0644]
trap.c~
variables.c
version.c
version2.c

index f5ae4ed062819fd84b791b2fbdd9984238f5ed5d..a197a0e64f9f080a2990d99084e5227a78a20c86 100644 (file)
@@ -6790,7 +6790,8 @@ subst.c
                                   ----
 variables.c
        - initialize_shell_variables: when importing function definitions from
-         environment, use SEVAL_ONECMD flag for parse_and_execute
+         environment, use SEVAL_ONECMD flag for parse_and_execute.  Part of
+         CVE-2014-6271
 
 builtins/evalstring.c
        - parse_and_execute: if SEVAL_ONECMD flag set, return immediately after
@@ -6812,11 +6813,12 @@ parse.y
 parse.y
        - push_heredoc: new function, pushes a here-doc redirection onto
          redir_stack handling overflow of redir_stack. Exits on overflow.
-         Original fix from Florian Weimer <fweimer@redhat.com>
+         Original fix from Florian Weimer <fweimer@redhat.com>.  Fix for
+         CVE-2014-7186
        - change straight assignments to redir_stack to call push_redir
        - add one to size of word_lineno stack to avoid off-by-one error
          below in read_token_word. Overflow just results in line numbers
-         being wrong
+         being wrong.  Fix for CVE-2014-7187
 
                                   9/27
                                   ----
@@ -6846,7 +6848,86 @@ copy_cmd.c
        - copy_redirects: before calling savestring on here_doc_eof, make
          sure it's not NULL (it could have been the result of a here
          document delimited by EOF or EOS).  Fixes bug reported by
-         Michal Zalewski <lcamtuf@coredump.cx>.
+         Michal Zalewski <lcamtuf@coredump.cx>.  Fix for CVE-2014-6277
 
 make_cmd.c
-       - make_redirection: initialize here_doc_eof member to NULL
+       - make_redirection: initialize here_doc_eof member to NULL.  Rest of
+         fix for CVE-2014-6277
+
+                                  9/29
+                                  ----
+parse.y
+       - current_input_line_state: return a sh_input_line_state_t containing
+         the current shell_input_line and its index and size variables
+
+shell.h
+       - current_input_line_state: extern declaration
+
+builtins/evalstring.c
+       - parse_and_execute: call reset_parser() before returning if
+         SEVAL_ONECMD set.  Fixes bug reported by Michal Zalewski
+         <lcamtuf@coredump.cx> and designated CVE-2014-6278
+       - parse_and_execute: if we parse a function definition when
+         SEVAL_FUNCDEF is set, but don't consume the entire passed string,
+         throw an error, reset the parser, and return.  Part of fix for
+         CVE-2014-6278
+       - parse_and_execute: if parsing the shell function definition when
+         SEVAL_FUNCDEF is set transforms the function name (e.g., if it
+         begins with a newline or begins or ends with whitespace), throw
+         an error, reset the parser, and return.  Fixes bug reported by
+         Eric Kobrin <ekobrin@akamai.com>
+
+                                  10/2
+                                  ----
+jobs.c
+       - bgp_prune: don't do anything if bgpids.npid == 0 or bgpids.list == NULL.
+         This can happen if something gets run before the job control framework
+         is initialized.  Bug report from <mancha1@zoho.com>
+
+                                  10/3
+                                  ----
+parse.y
+       - xparse_dolparen: don't set token_to_read to newline after calling
+         parse_string() and cleaning up when the shell is not interactive.  This
+         makes the parser thing it's ok to read new commands even if it's not in
+         a state where that should be possible.  Underlying fix for bug reported
+         by Michal Zalewski <lcamtuf@coredump.cx> and designated CVE-6278
+       - parser_remaining_input: new function, returns the portion of
+         shell_input_line that hasn't yet been read
+       - current_input_line_state: removed
+
+shell.h
+       - parser_remaining_input: extern declaration
+       - current_input_line_state: removed
+
+builtins/evalstring.c
+       - parse_and_execute: change code that checks whether parse_command has
+         consumed the entire passed string when SEVAL_FUNCDEF is used to use
+         parser_remaining_input instead of messing around with (new)
+         current_input_line_state.  Part of fix for CVE-2014-6278
+
+variables.c
+       - initialize_shell_variables: if we don't call parse_and_execute, free the
+         temporary string, since parse_and_execute won't.  Report and fix from
+         Eric Kobrin <ekobrin@akamai.com>
+
+                                  10/4
+                                  ----
+print_cmd.c
+       - print_function_def: when in posix mode, print shell function
+         definitions as posix specifies them, without the leading
+         `function' keyword
+
+general.c
+       - exportable_function_name: return 1 if the passed string can be
+         added to the environment as an exported function name.  Currently
+         prohibits function names containing  `/' and `=' from being
+         exported
+
+general.h
+       - exportable_function_name: extern declaration
+
+builtins/setattr.def
+       - set_or_show_attributes: if exporting a function with export -f,
+         call exportable_function_name to determine whether the function
+         should be exported; don't export function if it returns 0
index 4fe946bbc043e7bd8e0cf139a121ce889a13014a..4c60f71d7e56f0754793d4083ada4ff0fecfb13e 100644 (file)
@@ -6790,7 +6790,8 @@ subst.c
                                   ----
 variables.c
        - initialize_shell_variables: when importing function definitions from
-         environment, use SEVAL_ONECMD flag for parse_and_execute
+         environment, use SEVAL_ONECMD flag for parse_and_execute.  Part of
+         CVE-2014-6271
 
 builtins/evalstring.c
        - parse_and_execute: if SEVAL_ONECMD flag set, return immediately after
@@ -6812,11 +6813,12 @@ parse.y
 parse.y
        - push_heredoc: new function, pushes a here-doc redirection onto
          redir_stack handling overflow of redir_stack. Exits on overflow.
-         Original fix from Florian Weimer <fweimer@redhat.com>
+         Original fix from Florian Weimer <fweimer@redhat.com>.  Fix for
+         CVE-2014-7186
        - change straight assignments to redir_stack to call push_redir
        - add one to size of word_lineno stack to avoid off-by-one error
          below in read_token_word. Overflow just results in line numbers
-         being wrong
+         being wrong.  Fix for CVE-2014-7187
 
                                   9/27
                                   ----
@@ -6846,4 +6848,72 @@ copy_cmd.c
        - copy_redirects: before calling savestring on here_doc_eof, make
          sure it's not NULL (it could have been the result of a here
          document delimited by EOF or EOS).  Fixes bug reported by
-         Michal Zalewski <lcamtuf@coredump.cx>.
+         Michal Zalewski <lcamtuf@coredump.cx>.  Fix for CVE-2014-6277
+
+make_cmd.c
+       - make_redirection: initialize here_doc_eof member to NULL.  Rest of
+         fix for CVE-2014-6277
+
+                                  9/29
+                                  ----
+parse.y
+       - current_input_line_state: return a sh_input_line_state_t containing
+         the current shell_input_line and its index and size variables
+
+shell.h
+       - current_input_line_state: extern declaration
+
+builtins/evalstring.c
+       - parse_and_execute: call reset_parser() before returning if
+         SEVAL_ONECMD set.  Fixes bug reported by Michal Zalewski
+         <lcamtuf@coredump.cx> and designated CVE-2014-6278
+       - parse_and_execute: if we parse a function definition when
+         SEVAL_FUNCDEF is set, but don't consume the entire passed string,
+         throw an error, reset the parser, and return.  Part of fix for
+         CVE-2014-6278
+       - parse_and_execute: if parsing the shell function definition when
+         SEVAL_FUNCDEF is set transforms the function name (e.g., if it
+         begins with a newline or begins or ends with whitespace), throw
+         an error, reset the parser, and return.  Fixes bug reported by
+         Eric Kobrin <ekobrin@akamai.com>
+
+                                  10/2
+                                  ----
+jobs.c
+       - bgp_prune: don't do anything if bgpids.npid == 0 or bgpids.list == NULL.
+         This can happen if something gets run before the job control framework
+         is initialized.  Bug report from <mancha1@zoho.com>
+
+                                  10/3
+                                  ----
+parse.y
+       - xparse_dolparen: don't set token_to_read to newline after calling
+         parse_string() and cleaning up when the shell is not interactive.  This
+         makes the parser thing it's ok to read new commands even if it's not in
+         a state where that should be possible.  Underlying fix for bug reported
+         by Michal Zalewski <lcamtuf@coredump.cx> and designated CVE-6278
+       - parser_remaining_input: new function, returns the portion of
+         shell_input_line that hasn't yet been read
+       - current_input_line_state: removed
+
+shell.h
+       - parser_remaining_input: extern declaration
+       - current_input_line_state: removed
+
+builtins/evalstring.c
+       - parse_and_execute: change code that checks whether parse_command has
+         consumed the entire passed string when SEVAL_FUNCDEF is used to use
+         parser_remaining_input instead of messing around with (new)
+         current_input_line_state.  Part of fix for CVE-2014-6278
+
+variables.c
+       - initialize_shell_variables: if we don't call parse_and_execute, free the
+         temporary string, since parse_and_execute won't.  Report and fix from
+         Eric Kobrin <ekobrin@akamai.com>
+
+                                  10/4
+                                  ----
+print_cmd.c
+       - print_function_def: when in posix mode, print shell function
+         definitions as posix specifies them, without the leading
+         `function' keyword
index d81c68d625631ee04f358ffdb8a5d33cfe81aee6..aff06c8aaeb3309db1961b297093515cfa0afc27 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -938,6 +938,11 @@ tests/exp3.sub             f
 tests/exp4.sub         f
 tests/exp5.sub         f
 tests/exp6.sub         f
+tests/exportfunc.tests f
+tests/exportfunc.right f
+tests/exportfunc1.sub  f
+tests/exportfunc2.sub  f
+tests/exportfunc3.sub  f
 tests/extglob.tests    f
 tests/extglob.right    f
 tests/extglob1.sub     f
@@ -1131,6 +1136,7 @@ tests/run-dollars f
 tests/run-errors       f
 tests/run-execscript   f
 tests/run-exp-tests    f
+tests/run-exportfunc   f
 tests/run-extglob      f
 tests/run-extglob2     f
 tests/run-extglob3     f
diff --git a/MANIFEST~ b/MANIFEST~
new file mode 100644 (file)
index 0000000..85dcac6
--- /dev/null
+++ b/MANIFEST~
@@ -0,0 +1,1300 @@
+#
+# Master distribution manifest for bash
+#
+#
+# Filename     type
+#
+CWRU           d
+CWRU/misc      d
+builtins       d
+cross-build    d
+doc    d
+examples       d
+#examples/obashdb      d
+examples/complete      d
+examples/functions d
+examples/scripts d
+#examples/scripts.v2   d
+#examples/scripts.noah d
+examples/startup-files d
+#examples/startup-files/apple  d
+examples/misc  d
+examples/loadables d
+examples/loadables/perl        d
+include                d
+lib            d
+lib/glob       d
+lib/glob/doc   d
+lib/intl       d
+lib/malloc     d
+lib/readline   d
+lib/readline/doc d
+lib/readline/examples d
+lib/sh         d
+lib/termcap    d
+lib/tilde      d
+m4             d
+po             d
+support                d
+tests          d
+tests/misc     d
+ABOUT-NLS      f
+ChangeLog      s       CWRU/changelog
+CHANGES                f
+COMPAT         f
+COPYING                f
+INSTALL                f
+MANIFEST       f
+NEWS           f
+NOTES          f
+POSIX          f
+README         f
+RBASH          f
+AUTHORS                f
+Y2K            f
+configure.ac   f
+configure      f       755
+Makefile.in    f
+config-top.h   f
+config-bot.h   f
+config.h.in    f
+aclocal.m4     f
+array.c                f
+arrayfunc.c    f
+assoc.c                f
+eval.c         f
+print_cmd.c    f
+general.c      f
+list.c         f
+locale.c       f
+stringlib.c    f
+variables.c    f
+make_cmd.c     f
+copy_cmd.c     f
+unwind_prot.c  f
+dispose_cmd.c  f
+bashhist.c     f
+hashcmd.c      f
+hashlib.c      f
+parse.y                f
+pathexp.c      f
+subst.c                f
+shell.c                f
+trap.c         f
+sig.c          f
+siglist.c      f
+version.c      f
+flags.c                f
+jobs.c         f
+input.c                f
+mailcheck.c    f
+test.c         f
+expr.c         f
+alias.c                f
+execute_cmd.c  f
+findcmd.c      f
+redir.c                f
+bashline.c     f
+braces.c       f
+bracecomp.c    f
+nojobs.c       f
+error.c                f
+xmalloc.c      f
+pcomplete.c    f
+pcomplib.c     f
+mksyntax.c     f
+alias.h                f
+builtins.h     f
+bashhist.h     f
+bashline.h     f
+conftypes.h    f
+patchlevel.h   f
+variables.h    f
+array.h                f
+arrayfunc.h    f
+assoc.h                f
+jobs.h         f
+findcmd.h      f
+hashlib.h      f
+quit.h         f
+flags.h                f
+shell.h                f
+syntax.h       f
+pathexp.h      f
+parser.h       f
+pcomplete.h    f
+sig.h          f
+test.h         f
+trap.h         f
+general.h      f
+unwind_prot.h  f
+input.h                f
+error.h                f
+command.h      f
+externs.h      f
+siglist.h      f
+subst.h                f
+dispose_cmd.h  f
+hashcmd.h      f
+bashansi.h     f
+bashjmp.h      f
+bashintl.h     f
+make_cmd.h     f
+execute_cmd.h  f
+redir.h                f
+bashtypes.h    f
+mailcheck.h    f
+xmalloc.h      f
+y.tab.c                f
+y.tab.h                f
+parser-built   f
+pathnames.h.in f
+builtins/Makefile.in   f
+builtins/alias.def     f
+builtins/bind.def      f
+builtins/break.def     f
+builtins/builtin.def   f
+builtins/caller.def    f
+builtins/cd.def                f
+builtins/colon.def     f
+builtins/command.def   f
+builtins/complete.def  f
+builtins/common.c      f
+builtins/declare.def   f
+builtins/echo.def      f
+builtins/enable.def    f
+builtins/eval.def      f
+builtins/evalfile.c    f
+builtins/evalstring.c  f
+builtins/exec.def      f
+builtins/exit.def      f
+builtins/fc.def                f
+builtins/fg_bg.def     f
+builtins/gen-helpfiles.c       f
+builtins/getopt.c      f
+builtins/getopt.h      f
+builtins/getopts.def   f
+builtins/hash.def      f
+builtins/help.def      f
+builtins/let.def       f
+builtins/history.def   f
+builtins/jobs.def      f
+builtins/kill.def      f
+builtins/mapfile.def   f
+builtins/mkbuiltins.c  f
+builtins/printf.def    f
+builtins/pushd.def     f
+builtins/read.def      f
+builtins/reserved.def  f
+builtins/return.def    f
+builtins/set.def       f
+builtins/setattr.def   f
+builtins/shift.def     f
+builtins/shopt.def     f
+builtins/source.def    f
+builtins/suspend.def   f
+builtins/test.def      f
+builtins/times.def     f
+builtins/trap.def      f
+builtins/type.def      f
+builtins/ulimit.def    f
+builtins/umask.def     f
+builtins/wait.def      f
+builtins/psize.c       f
+builtins/psize.sh      f
+builtins/inlib.def     f
+builtins/bashgetopt.c  f
+builtins/common.h      f
+builtins/bashgetopt.h  f
+cross-build/cygwin32.cache     f
+cross-build/x86-beos.cache     f
+cross-build/opennt.cache       f
+include/ansi_stdlib.h  f
+include/chartypes.h    f
+include/filecntl.h     f
+include/gettext.h      f
+include/maxpath.h      f
+include/memalloc.h     f
+include/ocache.h       f
+include/posixdir.h     f
+include/posixjmp.h     f
+include/posixselect.h  f
+include/posixstat.h    f
+include/posixtime.h    f
+include/posixwait.h    f
+include/shmbchar.h     f
+include/shmbutil.h     f
+include/shtty.h                f
+include/stat-time.h    f
+include/stdc.h         f
+include/systimes.h     f
+include/typemax.h      f
+include/unionwait.h    f
+lib/glob/Makefile.in   f
+lib/glob/sm_loop.c     f
+lib/glob/smatch.c      f
+lib/glob/strmatch.c    f
+lib/glob/strmatch.h    f
+lib/glob/glob.c                f
+lib/glob/glob.h                f
+lib/glob/glob_loop.c   f
+lib/glob/gmisc.c       f
+lib/glob/xmbsrtowcs.c  f
+lib/glob/collsyms.h    f
+lib/glob/doc/Makefile  f
+lib/glob/doc/glob.texi f
+lib/glob/ndir.h                f
+lib/intl/ChangeLog     f
+lib/intl/Makefile.in   f
+lib/intl/VERSION       f
+lib/intl/bindtextdom.c f
+lib/intl/config.charset        f
+lib/intl/dcgettext.c   f
+lib/intl/dcigettext.c  f
+lib/intl/dcngettext.c  f
+lib/intl/dgettext.c    f
+lib/intl/dngettext.c   f
+lib/intl/eval-plural.h f
+lib/intl/explodename.c f
+lib/intl/finddomain.c  f
+lib/intl/gettext.c     f
+lib/intl/gettextP.h    f
+lib/intl/gmo.h         f
+lib/intl/hash-string.h f
+lib/intl/intl-compat.c f
+lib/intl/l10nflist.c   f
+lib/intl/libgnuintl.h.in       f
+lib/intl/loadinfo.h    f
+lib/intl/loadmsgcat.c  f
+lib/intl/localcharset.c        f
+lib/intl/localcharset.h        f
+lib/intl/locale.alias  f
+lib/intl/localealias.c f
+lib/intl/localename.c  f
+lib/intl/log.c         f
+lib/intl/ngettext.c    f
+lib/intl/os2compat.c   f
+lib/intl/os2compat.h   f
+lib/intl/osdep.c       f
+lib/intl/plural-exp.c  f
+lib/intl/plural-exp.h  f
+lib/intl/plural.c      f
+lib/intl/plural.y      f
+lib/intl/ref-add.sin   f
+lib/intl/ref-del.sin   f
+lib/intl/relocatable.c f
+lib/intl/relocatable.h f
+lib/intl/textdomain.c  f
+lib/malloc/Makefile.in f
+lib/malloc/getpagesize.h       f
+lib/malloc/imalloc.h   f
+lib/malloc/mstats.h    f
+lib/malloc/shmalloc.h  f
+lib/malloc/table.h     f
+lib/malloc/watch.h     f
+lib/malloc/alloca.c    f
+lib/malloc/malloc.c    f
+lib/malloc/stats.c     f
+lib/malloc/table.c     f
+lib/malloc/trace.c     f
+lib/malloc/watch.c     f
+lib/malloc/xmalloc.c   f
+lib/malloc/xleaktrace  f       755
+lib/malloc/stub.c      f
+lib/malloc/i386-alloca.s       f
+lib/malloc/x386-alloca.s       f
+lib/readline/COPYING   f
+lib/readline/Makefile.in       f
+lib/readline/ChangeLog f
+lib/readline/README    f
+lib/readline/STANDALONE f
+lib/readline/readline.c        f
+lib/readline/vi_mode.c f
+lib/readline/emacs_keymap.c    f
+lib/readline/vi_keymap.c       f
+lib/readline/history.c f
+lib/readline/histexpand.c      f
+lib/readline/histsearch.c      f
+lib/readline/histfile.c        f
+lib/readline/funmap.c  f
+lib/readline/keymaps.c f
+lib/readline/util.c    f
+lib/readline/terminal.c        f
+lib/readline/xfree.c   f
+lib/readline/xmalloc.c f
+lib/readline/search.c  f
+lib/readline/isearch.c f
+lib/readline/parens.c  f
+lib/readline/rltty.c   f
+lib/readline/compat.c  f
+lib/readline/complete.c        f
+lib/readline/bind.c    f
+lib/readline/display.c f
+lib/readline/signals.c f
+lib/readline/kill.c    f
+lib/readline/text.c    f
+lib/readline/undo.c    f
+lib/readline/macro.c   f
+lib/readline/input.c   f
+lib/readline/callback.c        f
+lib/readline/mbutil.c  f
+lib/readline/misc.c    f
+lib/readline/nls.c     f
+lib/readline/shell.c   f
+lib/readline/colors.c  f
+lib/readline/parse-colors.c    f
+lib/readline/savestring.c      f
+lib/readline/tilde.c   f
+lib/readline/tilde.h   f
+lib/readline/rldefs.h  f
+lib/readline/rlconf.h  f
+lib/readline/rlmbutil.h        f
+lib/readline/rlshell.h f
+lib/readline/rltty.h   f
+lib/readline/rltypedefs.h      f
+lib/readline/rlwinsize.h       f
+lib/readline/readline.h        f
+lib/readline/tcap.h    f
+lib/readline/keymaps.h f
+lib/readline/history.h f
+lib/readline/histlib.h f
+lib/readline/chardefs.h        f
+lib/readline/posixdir.h        f
+lib/readline/posixjmp.h        f
+lib/readline/posixselect.h     f
+lib/readline/posixstat.h       f
+lib/readline/ansi_stdlib.h     f
+lib/readline/rlstdc.h  f
+lib/readline/rlprivate.h       f
+lib/readline/colors.h  f
+lib/readline/parse-colors.h    f
+lib/readline/xmalloc.h f
+lib/readline/doc/Makefile      f
+lib/readline/doc/version.texi  f
+lib/readline/doc/rlman.texi    f
+lib/readline/doc/rltech.texi   f
+lib/readline/doc/rluser.texi   f
+lib/readline/doc/rluserman.texi        f
+lib/readline/doc/history.texi  f
+lib/readline/doc/hstech.texi   f
+lib/readline/doc/hsuser.texi   f
+lib/readline/doc/fdl.texi      f
+lib/readline/examples/Makefile f
+lib/readline/examples/excallback.c     f
+lib/readline/examples/fileman.c        f
+lib/readline/examples/manexamp.c       f
+lib/readline/examples/histexamp.c      f
+lib/readline/examples/rltest.c f
+lib/readline/examples/rl-callbacktest.c        f
+lib/readline/examples/rl.c     f
+lib/readline/examples/rlcat.c  f
+lib/readline/examples/Inputrc  f
+lib/sh/Makefile.in     f
+lib/sh/casemod.c       f
+lib/sh/clktck.c                f
+lib/sh/clock.c         f
+lib/sh/dprintf.c       f
+lib/sh/eaccess.c       f
+lib/sh/fmtullong.c     f
+lib/sh/fmtulong.c      f
+lib/sh/fmtumax.c       f
+lib/sh/fnxform.c       f
+lib/sh/fpurge.c                f
+lib/sh/getcwd.c                f
+lib/sh/getenv.c                f
+lib/sh/inet_aton.c     f
+lib/sh/input_avail.c   f
+lib/sh/itos.c          f
+lib/sh/mailstat.c      f
+lib/sh/makepath.c      f
+lib/sh/mbscasecmp.c    f
+lib/sh/mbschr.c                f
+lib/sh/mbscmp.c                f
+lib/sh/memset.c                f
+lib/sh/mktime.c                f
+lib/sh/netconn.c       f
+lib/sh/netopen.c       f
+lib/sh/oslib.c         f
+lib/sh/pathcanon.c     f
+lib/sh/pathphys.c      f
+lib/sh/rename.c                f
+lib/sh/setlinebuf.c    f
+lib/sh/shmatch.c       f
+lib/sh/shmbchar.c      f
+lib/sh/shquote.c       f
+lib/sh/shtty.c         f
+lib/sh/snprintf.c      f
+lib/sh/spell.c         f
+lib/sh/strcasecmp.c    f
+lib/sh/strcasestr.c    f
+lib/sh/strchrnul.c     f
+lib/sh/strdup.c                f
+lib/sh/strerror.c      f
+lib/sh/strftime.c      f
+lib/sh/stringlist.c    f
+lib/sh/stringvec.c     f
+lib/sh/strnlen.c       f
+lib/sh/strpbrk.c       f
+lib/sh/strstr.c                f
+lib/sh/strtod.c                f
+lib/sh/strtoimax.c     f
+lib/sh/strtol.c                f
+lib/sh/strtoll.c       f
+lib/sh/strtoul.c       f
+lib/sh/strtoull.c      f
+lib/sh/strtoumax.c     f
+lib/sh/strtrans.c      f
+lib/sh/times.c         f
+lib/sh/timeval.c       f
+lib/sh/tmpfile.c       f
+lib/sh/uconvert.c      f
+lib/sh/ufuncs.c                f
+lib/sh/unicode.c       f
+lib/sh/vprint.c                f
+lib/sh/wcsdup.c                f
+lib/sh/wcsnwidth.c     f
+lib/sh/wcswidth.c      f
+lib/sh/winsize.c       f
+lib/sh/zcatfd.c                f
+lib/sh/zgetline.c      f
+lib/sh/zmapfd.c                f
+lib/sh/zread.c         f
+lib/sh/zwrite.c                f
+lib/termcap/Makefile.in        f
+lib/termcap/ltcap.h    f
+lib/termcap/termcap.c  f
+lib/termcap/termcap.h  f
+lib/termcap/tparam.c   f
+lib/termcap/version.c  f
+lib/tilde/README       f
+lib/tilde/Makefile.in  f
+lib/tilde/tilde.c      f
+lib/tilde/tilde.h      f
+lib/tilde/shell.c      f
+m4/stat-time.m4                f
+m4/timespec.m4         f
+po/LINGUAS             f
+po/Makefile.in.in      f
+po/Makevars            f
+po/POTFILES.in         f
+po/README              f
+po/Rules-builtins      f
+po/Rules-quot          f
+po/bash.pot            f
+po/boldquot.sed                f
+po/en@boldquot.gmo     f
+po/en@boldquot.header  f
+po/en@boldquot.po      f
+po/en@quot.gmo         f
+po/en@quot.header      f
+po/en@quot.po          f
+po/af.gmo              f
+po/af.po               f
+po/bg.gmo              f
+po/bg.po               f
+po/ca.gmo              f
+po/ca.po               f
+po/cs.gmo              f
+po/cs.po               f
+po/da.gmo              f
+po/da.po               f
+po/de.gmo              f
+po/de.po               f
+po/el.gmo              f
+po/el.po               f
+po/eo.gmo              f
+po/eo.po               f
+po/es.gmo              f
+po/es.po               f
+po/et.gmo              f
+po/et.po               f
+po/fi.gmo              f
+po/fi.po               f
+po/fr.gmo              f
+po/fr.po               f
+po/ga.gmo              f
+po/ga.po               f
+po/gl.gmo              f
+po/gl.po               f
+po/hr.gmo              f
+po/hr.po               f
+po/hu.gmo              f
+po/hu.po               f
+po/id.gmo              f
+po/id.po               f
+po/it.gmo              f
+po/it.po               f
+po/ja.gmo              f
+po/ja.po               f
+po/lt.gmo              f
+po/lt.po               f
+po/nl.gmo              f
+po/nl.po               f
+po/pl.gmo              f
+po/pl.po               f
+po/pt_BR.gmo           f
+po/pt_BR.po            f
+po/ro.gmo              f
+po/ro.po               f
+po/ru.gmo              f
+po/ru.po               f
+po/sk.gmo              f
+po/sk.po               f
+po/sl.gmo              f
+po/sr.po               f
+po/sr.gmo              f
+po/sl.po               f
+po/sv.gmo              f
+po/sv.po               f
+po/tr.gmo              f
+po/tr.po               f
+po/uk.gmo              f
+po/uk.po               f
+po/vi.gmo              f
+po/vi.po               f
+po/zh_CN.gmo           f
+po/zh_CN.po            f
+po/zh_TW.gmo           f
+po/zh_TW.po            f
+po/insert-header.sin   f
+po/quot.sed            f
+po/remove-potcdate.sin f
+CWRU/misc/open-files.c f
+CWRU/misc/sigs.c       f
+CWRU/misc/sigstat.c    f
+CWRU/misc/bison                f
+CWRU/misc/errlist.c    f
+CWRU/misc/hpux10-dlfcn.h       f
+CWRU/PLATFORMS         f
+CWRU/README            f
+CWRU/changelog         f
+CWRU/sh-redir-hack     f
+doc/FAQ                f
+doc/Makefile.in        f
+doc/bash.1     f
+doc/bashbug.1  f
+doc/builtins.1 f
+doc/rbash.1    f
+doc/README     f
+doc/INTRO      f
+doc/texinfo.tex        f
+doc/bashref.texi       f
+doc/version.texi       f
+doc/bashref.info       f
+doc/article.ms f
+doc/htmlpost.sh        f       755
+doc/infopost.sh        f       755
+doc/fdl.texi   f
+doc/fdl.txt    f
+#
+doc/article.ps f
+doc/rose94.ps  f
+doc/bash.ps            f
+doc/bashbug.ps f
+doc/builtins.ps        f
+doc/rbash.ps   f
+doc/bashref.ps f
+doc/bashref.dvi        f
+doc/bash.0             f
+doc/bashbug.0          f
+doc/builtins.0 f
+doc/rbash.0    f
+doc/article.txt        f
+doc/bash.html          f
+doc/bashref.html       f
+doc/article.pdf        f
+doc/bash.pdf   f
+doc/bashref.pdf        f
+doc/rose94.pdf f
+doc/aosa-bash.pdf      f
+#
+support/Makefile.in    f
+support/bashversion.c  f
+support/checkbashisms  f       755
+support/config.guess   f
+support/config.rpath   f       755
+support/config.sub     f
+support/printenv.sh    f       755
+support/printenv.c     f
+support/bash.xbm       f
+support/missing                f       755
+support/mkclone                f       755
+support/mkconffiles    f       755
+support/mkdirs         f       755
+support/mkinstalldirs  f       755
+support/mkversion.sh   f       755
+support/mksignames.c   f
+support/signames.c     f
+support/bashbug.sh     f
+support/man2html.c     f
+support/recho.c                f
+support/zecho.c                f
+support/xcase.c                f
+support/SYMLINKS       f
+support/fixlinks       f       755
+support/install.sh     f       755
+support/texi2dvi       f       755
+support/texi2html      f       755
+support/xenix-link.sh  f       755
+support/shobj-conf     f       755
+support/rlvers.sh      f       755
+examples/INDEX.txt     f
+examples/INDEX.html    f
+#examples/obashdb/PERMISSION   f
+#examples/obashdb/README       f
+#examples/obashdb/bashdb               f
+#examples/obashdb/bashdb.el    f
+examples/complete/bash_completion      f
+examples/complete/cdfunc       f
+examples/complete/complete-examples    f
+#examples/complete/complete.ianmac     f
+#examples/complete/complete2.ianmac    f
+#examples/complete/complete.freebsd    f
+#examples/complete/complete.gnu-longopt        f
+examples/complete/bashcc-1.0.1.tar.gz  f
+examples/loadables/README      f
+examples/loadables/template.c  f
+examples/loadables/Makefile.in f
+examples/loadables/necho.c     f
+examples/loadables/hello.c     f
+examples/loadables/print.c     f
+examples/loadables/realpath.c  f
+examples/loadables/sleep.c     f
+examples/loadables/strftime.c  f
+examples/loadables/truefalse.c f
+#examples/loadables/getconf.h  f
+#examples/loadables/getconf.c  f
+examples/loadables/finfo.c     f
+examples/loadables/cat.c       f
+#examples/loadables/cut.c      f
+examples/loadables/logname.c   f
+examples/loadables/basename.c  f
+examples/loadables/dirname.c   f
+examples/loadables/tty.c       f
+examples/loadables/pathchk.c   f
+examples/loadables/tee.c       f
+examples/loadables/rmdir.c     f
+examples/loadables/head.c      f
+examples/loadables/printenv.c  f
+examples/loadables/push.c      f
+examples/loadables/id.c                f
+examples/loadables/whoami.c    f
+examples/loadables/uname.c     f
+examples/loadables/sync.c      f
+examples/loadables/mkdir.c     f
+examples/loadables/ln.c                f
+examples/loadables/mypid.c     f
+examples/loadables/unlink.c    f
+examples/loadables/perl/Makefile.in    f
+examples/loadables/perl/README f
+examples/loadables/perl/bperl.c        f
+examples/loadables/perl/iperl.c        f
+#examples/loadables/sprintf.c  f
+#examples/loadables/xtitle.c   f
+examples/functions/array-stuff f
+examples/functions/array-to-string     f
+examples/functions/autoload    f
+examples/functions/autoload.v2 f
+examples/functions/autoload.v3 f
+examples/functions/basename    f
+#examples/functions/basename2  f
+#examples/functions/coproc.bash        f
+#examples/functions/coshell.README     f
+#examples/functions/coshell.bash       f
+examples/functions/csh-compat  f
+#examples/functions/dirfuncs   f
+examples/functions/dirname     f
+examples/functions/dirstack    f
+#examples/functions/emptydir   f
+examples/functions/exitstat    f
+examples/functions/external    f
+examples/functions/fact                f
+examples/functions/fstty       f
+examples/functions/func                f
+#examples/functions/gethtml    f
+#examples/functions/getoptx.bash       f
+examples/functions/inetaddr    f
+examples/functions/inpath      f
+#examples/functions/isnum.bash f
+examples/functions/isnum2      f
+examples/functions/isvalidip   f
+#examples/functions/jdate.bash f
+#examples/functions/jj.bash    f
+#examples/functions/keep               f
+examples/functions/ksh-cd      f
+examples/functions/ksh-compat-test     f
+examples/functions/kshenv      f
+examples/functions/login       f
+#examples/functions/lowercase  f
+#examples/functions/manpage    f
+#examples/functions/mhfold     f
+#examples/functions/newdirstack.bsh    f
+examples/functions/notify.bash f
+#examples/functions/pathfuncs  f
+#examples/functions/recurse    f
+#examples/functions/repeat2    f
+#examples/functions/repeat3    f
+examples/functions/seq         f
+examples/functions/seq2                f
+examples/functions/shcat       f
+examples/functions/shcat2      f
+examples/functions/sort-pos-params     f
+#examples/functions/sqroot     f
+examples/functions/substr      f
+examples/functions/substr2     f
+#examples/functions/term               f
+examples/functions/whatis      f
+examples/functions/whence      f
+examples/functions/which       f
+#examples/functions/xalias.bash        f
+#examples/functions/xfind.bash f
+#examples/scripts/adventure.sh f
+#examples/scripts/bash-hexdump.sh      f
+#examples/scripts/bcsh.sh      f
+examples/scripts/cat.sh                f
+examples/scripts/center                f
+#examples/scripts/dd-ex.sh     f
+#examples/scripts/fixfiles.bash        f
+#examples/scripts/hanoi.bash   f
+examples/scripts/inpath                f
+#examples/scripts/krand.bash   f
+#examples/scripts/line-input.bash      f
+#examples/scripts/nohup.bash   f
+#examples/scripts/precedence   f
+#examples/scripts/randomcard.bash      f
+#examples/scripts/scrollbar    f
+#examples/scripts/scrollbar2   f
+#examples/scripts/self-repro   f
+#examples/scripts/showperm.bash        f
+examples/scripts/shprompt      f
+examples/scripts/spin.bash     f
+#examples/scripts/timeout      f
+#examples/scripts/timeout2     f
+#examples/scripts/timeout3     f
+#examples/scripts/vtree2               f
+#examples/scripts/vtree3               f
+#examples/scripts/vtree3a      f
+#examples/scripts/websrv.sh    f
+examples/scripts/xterm_title   f
+examples/scripts/zprintf       f
+examples/startup-files/README  f
+examples/startup-files/Bashrc.bfox     f
+examples/startup-files/Bash_aliases    f
+examples/startup-files/Bash_profile    f
+examples/startup-files/bash-profile    f
+examples/startup-files/bashrc  f
+#examples/startup-files/apple/README   f
+#examples/startup-files/apple/aliases  f
+#examples/startup-files/apple/bash.defaults    f
+#examples/startup-files/apple/environment      f
+#examples/startup-files/apple/login    f
+#examples/startup-files/apple/logout   f
+#examples/startup-files/apple/rc               f
+#examples/misc/suncmd.termcap  f
+examples/misc/aliasconv.sh     f
+examples/misc/aliasconv.bash   f
+examples/misc/cshtobash        f
+tests/README           f
+tests/COPYRIGHT                f
+tests/alias.tests      f
+tests/alias1.sub       f
+tests/alias.right      f
+tests/appendop.tests   f
+tests/appendop1.sub    f
+tests/appendop2.sub    f
+tests/appendop.right   f
+tests/arith-for.tests  f
+tests/arith-for.right  f
+tests/arith.tests      f
+tests/arith.right      f
+tests/arith1.sub       f
+tests/arith2.sub       f
+tests/arith3.sub       f
+tests/arith4.sub       f
+tests/arith5.sub       f
+tests/arith6.sub       f
+tests/array.tests      f
+tests/array.right      f
+tests/array1.sub       f
+tests/array2.sub       f
+tests/array3.sub       f
+tests/array4.sub       f
+tests/array5.sub       f
+tests/array6.sub       f
+tests/array7.sub       f
+tests/array8.sub       f
+tests/array9.sub       f
+tests/array10.sub      f
+tests/array11.sub      f
+tests/array12.sub      f
+tests/array13.sub      f
+tests/array14.sub      f
+tests/array15.sub      f
+tests/array16.sub      f
+tests/array-at-star    f
+tests/array2.right     f
+tests/assoc.tests      f
+tests/assoc.right      f
+tests/assoc1.sub       f
+tests/assoc2.sub       f
+tests/assoc3.sub       f
+tests/assoc4.sub       f
+tests/assoc5.sub       f
+tests/assoc6.sub       f
+tests/assoc7.sub       f
+tests/braces.tests     f
+tests/braces.right     f
+tests/builtins.tests   f
+tests/builtins.right   f
+tests/builtins1.sub    f
+tests/builtins2.sub    f
+tests/builtins3.sub    f
+tests/builtins4.sub    f
+tests/source1.sub      f
+tests/source2.sub      f
+tests/source3.sub      f
+tests/source4.sub      f
+tests/source5.sub      f
+tests/source6.sub      f
+tests/source7.sub      f
+tests/case.tests       f
+tests/case.right       f
+tests/case1.sub                f
+tests/casemod.tests    f
+tests/casemod.right    f
+tests/comsub.tests     f
+tests/comsub.right     f
+tests/comsub1.sub      f
+tests/comsub-eof.tests f
+tests/comsub-eof0.sub  f
+tests/comsub-eof1.sub  f
+tests/comsub-eof2.sub  f
+tests/comsub-eof3.sub  f
+tests/comsub-eof4.sub  f
+tests/comsub-eof5.sub  f
+tests/comsub-eof.right f
+tests/comsub-posix.tests       f
+tests/comsub-posix.right       f
+tests/comsub-posix1.sub        f
+tests/comsub-posix2.sub        f
+tests/comsub-posix3.sub        f
+tests/cond.tests       f
+tests/cond.right       f
+tests/cond-regexp1.sub f
+tests/cond-regexp2.sub f
+tests/cond-regexp3.sub f
+tests/coproc.tests     f
+tests/coproc.right     f
+tests/cprint.tests     f
+tests/cprint.right     f
+tests/dbg-support.right        f
+tests/dbg-support.sub  f
+tests/dbg-support.tests        f
+tests/dbg-support2.right       f
+tests/dbg-support2.tests       f
+tests/dbg-support3.sub f
+tests/dollar-at-star   f
+tests/dollar-at-star1.sub      f
+tests/dollar-at-star2.sub      f
+tests/dollar-at1.sub   f
+tests/dollar-at2.sub   f
+tests/dollar-at3.sub   f
+tests/dollar-at4.sub   f
+tests/dollar-at5.sub   f
+tests/dollar-at6.sub   f
+tests/dollar-star1.sub f
+tests/dollar-star2.sub f
+tests/dollar-star3.sub f
+tests/dollar-star4.sub f
+tests/dollar-star5.sub f
+tests/dollar-star6.sub f
+tests/dollar-star7.sub f
+tests/dollar.right     f
+tests/dstack.tests     f
+tests/dstack.right     f
+tests/dstack2.tests    f
+tests/dstack2.right    f
+tests/errors.tests     f
+tests/errors.right     f
+tests/errors1.sub      f
+tests/errors2.sub      f
+tests/errors3.sub      f
+tests/execscript       f
+tests/exec.right       f
+tests/exec1.sub                f       755
+tests/exec2.sub                f
+tests/exec3.sub                f
+tests/exec4.sub                f
+tests/exec5.sub                f
+tests/exec6.sub                f
+tests/exec7.sub                f
+tests/exec8.sub                f
+tests/exec9.sub                f
+tests/exp.tests                f
+tests/exp.right                f
+tests/exp1.sub         f
+tests/exp2.sub         f
+tests/exp3.sub         f
+tests/exp4.sub         f
+tests/exp5.sub         f
+tests/exp6.sub         f
+tests/exportfunc.tests f
+tests/exportfunc.right f
+tests/exportfunc1.sub  f
+tests/exportfunc2.sub  f
+tests/extglob.tests    f
+tests/extglob.right    f
+tests/extglob1.sub     f
+tests/extglob1a.sub    f
+tests/extglob3.sub     f
+tests/extglob2.tests   f
+tests/extglob2.right   f
+tests/extglob3.tests   f
+tests/extglob3.right   f
+tests/func.tests       f
+tests/func.right       f
+tests/func1.sub                f
+tests/func2.sub                f
+tests/func3.sub                f
+tests/func4.sub                f
+tests/getopts.tests    f
+tests/getopts.right    f
+tests/getopts1.sub     f
+tests/getopts2.sub     f
+tests/getopts3.sub     f
+tests/getopts4.sub     f
+tests/getopts5.sub     f
+tests/getopts6.sub     f
+tests/getopts7.sub     f
+tests/glob.tests       f
+tests/glob1.sub                f
+tests/glob.right       f
+tests/globstar.tests   f
+tests/globstar.right   f
+tests/globstar1.sub    f
+tests/globstar2.sub    f
+tests/heredoc.tests    f
+tests/heredoc.right    f
+tests/heredoc1.sub     f
+tests/heredoc2.sub     f
+tests/heredoc3.sub     f
+tests/herestr.tests    f
+tests/herestr.right    f
+tests/histexp.tests    f
+tests/histexp.right    f
+tests/history.tests    f
+tests/history.right    f
+tests/history.list     f       444
+tests/history1.sub     f
+tests/history2.sub     f
+tests/ifs.tests                f
+tests/ifs.right                f
+tests/ifs-posix.tests  f
+tests/ifs-posix.right  f
+tests/input-line.sh    f
+tests/input-line.sub   f
+tests/input.right      f
+tests/intl.tests       f
+tests/intl1.sub                f
+tests/intl2.sub                f
+tests/intl.right       f
+tests/iquote.tests     f
+tests/iquote.right     f
+tests/iquote1.sub      f
+tests/invert.tests     f
+tests/invert.right     f
+tests/jobs.tests       f
+tests/jobs1.sub                f
+tests/jobs2.sub                f
+tests/jobs3.sub                f
+tests/jobs4.sub                f
+tests/jobs5.sub                f
+tests/jobs.right       f
+tests/lastpipe.right   f
+tests/lastpipe.tests   f
+tests/lastpipe1.sub    f
+tests/mapfile.data     f
+tests/mapfile.right    f
+tests/mapfile.tests    f
+tests/mapfile1.sub     f
+tests/mapfile2.sub     f
+tests/more-exp.tests   f
+tests/more-exp.right   f
+tests/nameref.tests    f
+tests/nameref1.sub     f
+tests/nameref2.sub     f
+tests/nameref3.sub     f
+tests/nameref4.sub     f
+tests/nameref5.sub     f
+tests/nameref6.sub     f
+tests/nameref7.sub     f
+tests/nameref8.sub     f
+tests/nameref.right    f
+tests/new-exp.tests    f
+tests/new-exp1.sub     f
+tests/new-exp2.sub     f
+tests/new-exp3.sub     f
+tests/new-exp4.sub     f
+tests/new-exp5.sub     f
+tests/new-exp6.sub     f
+tests/new-exp7.sub     f
+tests/new-exp8.sub     f
+tests/new-exp9.sub     f
+tests/new-exp.right    f
+tests/nquote.tests     f
+tests/nquote.right     f
+tests/nquote1.sub      f
+tests/nquote2.sub      f
+tests/nquote1.tests    f
+tests/nquote1.right    f
+tests/nquote2.tests    f
+tests/nquote2.right    f
+tests/nquote3.tests    f
+tests/nquote3.right    f
+tests/nquote4.tests    f
+tests/nquote4.right    f
+tests/nquote5.tests    f
+tests/nquote5.right    f
+tests/parser.tests     f
+tests/parser.right     f
+tests/parser1.sub      f
+tests/posix2.tests     f
+tests/posix2.right     f
+tests/posixexp.tests   f
+tests/posixexp.right   f
+tests/posixexp1.sub    f
+tests/posixexp2.sub    f
+tests/posixexp2.tests  f
+tests/posixexp2.right  f
+tests/posixpat.tests   f
+tests/posixpat.right   f
+tests/posixpipe.tests  f
+tests/posixpipe.right  f
+tests/prec.right       f
+tests/precedence       f
+tests/printf.tests     f
+tests/printf.right     f
+tests/printf1.sub      f
+tests/printf2.sub      f
+tests/printf3.sub      f
+tests/printf4.sub      f
+tests/quote.tests      f
+tests/quote.right      f
+tests/quote1.sub       f
+tests/read.tests       f
+tests/read.right       f
+tests/read1.sub                f
+tests/read2.sub                f
+tests/read3.sub                f
+tests/read4.sub                f
+tests/read5.sub                f
+tests/read6.sub                f
+tests/redir.tests      f
+tests/redir.right      f
+tests/redir1.sub       f
+tests/redir2.sub       f
+tests/redir3.sub       f
+tests/redir3.in1       f
+tests/redir3.in2       f
+tests/redir4.sub       f
+tests/redir4.in1       f
+tests/redir5.sub       f
+tests/redir6.sub       f
+tests/redir7.sub       f
+tests/redir8.sub       f
+tests/redir9.sub       f
+tests/redir10.sub      f
+tests/rhs-exp.tests    f
+tests/rhs-exp.right    f
+tests/rhs-exp1.sub     f
+tests/rsh.tests                f
+tests/rsh.right                f
+tests/run-all          f
+tests/run-minimal      f
+tests/run-alias                f
+tests/run-appendop     f
+tests/run-arith-for    f
+tests/run-arith                f
+tests/run-array                f
+tests/run-array2       f
+tests/run-assoc                f
+tests/run-braces       f
+tests/run-builtins     f
+tests/run-case         f
+tests/run-casemod      f
+tests/run-comsub       f
+tests/run-comsub-eof   f
+tests/run-comsub-posix f
+tests/run-cond         f
+tests/run-coproc       f
+tests/run-cprint       f
+tests/run-dbg-support  f
+tests/run-dbg-support2 f
+tests/run-dirstack     f
+tests/run-dollars      f
+tests/run-errors       f
+tests/run-execscript   f
+tests/run-exp-tests    f
+tests/run-exportfunc   f
+tests/run-extglob      f
+tests/run-extglob2     f
+tests/run-extglob3     f
+tests/run-func         f
+tests/run-getopts      f
+tests/run-glob-test    f
+tests/run-globstar     f
+tests/run-heredoc      f
+tests/run-herestr      f
+tests/run-histexpand   f
+tests/run-history      f
+tests/run-ifs          f
+tests/run-ifs-posix    f
+tests/run-input-test   f
+tests/run-intl         f
+tests/run-iquote       f
+tests/run-invert       f
+tests/run-jobs         f
+tests/run-lastpipe     f
+tests/run-mapfile      f
+tests/run-more-exp     f
+tests/run-nameref      f
+tests/run-new-exp      f
+tests/run-nquote       f
+tests/run-nquote1      f
+tests/run-nquote2      f
+tests/run-nquote3      f
+tests/run-nquote4      f
+tests/run-nquote5      f
+tests/run-parser       f
+tests/run-posix2       f
+tests/run-posixexp     f
+tests/run-posixexp2    f
+tests/run-posixpat     f
+tests/run-posixpipe    f
+tests/run-precedence   f
+tests/run-printf       f
+tests/run-quote                f
+tests/run-read         f
+tests/run-redir                f
+tests/run-rhs-exp      f
+tests/run-rsh          f
+tests/run-set-e                f
+tests/run-set-x                f
+tests/run-shopt                f
+tests/run-strip                f
+tests/run-test         f
+tests/run-tilde                f
+tests/run-tilde2       f
+tests/run-trap         f
+tests/run-type         f
+tests/run-varenv       f
+tests/run-vredir       f
+tests/set-e.tests      f
+tests/set-e1.sub       f
+tests/set-e2.sub       f
+tests/set-e3.sub       f
+tests/set-e3a.sub      f
+tests/set-e.right      f
+tests/set-x.tests      f
+tests/set-x1.sub       f
+tests/set-x.right      f
+tests/shopt.tests      f       
+tests/shopt.right      f
+tests/strip.tests      f
+tests/strip.right      f
+tests/test.tests       f
+tests/test.right       f
+tests/tilde.tests      f
+tests/tilde.right      f
+tests/tilde2.tests     f
+tests/tilde2.right     f
+tests/trap.tests       f
+tests/trap.right       f
+tests/trap1.sub                f       755
+tests/trap2.sub                f       755
+tests/trap2a.sub       f       755
+tests/trap3.sub                f
+tests/trap4.sub                f
+tests/trap5.sub                f
+tests/type.tests       f
+tests/type.right       f
+tests/type1.sub                f
+tests/type2.sub                f
+tests/type3.sub                f
+tests/type4.sub                f
+tests/unicode1.sub     f
+tests/unicode2.sub     f
+tests/unicode3.sub     f
+tests/varenv.right     f
+tests/varenv.sh                f
+tests/varenv1.sub      f
+tests/varenv2.sub      f
+tests/varenv3.sub      f
+tests/varenv4.sub      f
+tests/varenv5.sub      f
+tests/varenv6.sub      f
+tests/version          f
+tests/version.mini     f
+tests/vredir.tests     f
+tests/vredir.right     f
+tests/vredir1.sub      f
+tests/vredir2.sub      f
+tests/vredir3.sub      f
+tests/vredir4.sub      f
+tests/vredir5.sub      f
+tests/vredir6.sub      f
+tests/misc/dev-tcp.tests       f
+tests/misc/perf-script f
+tests/misc/perftest    f
+tests/misc/read-nchars.tests   f
+tests/misc/redir-t2.sh f
+tests/misc/run-r2.sh   f
+tests/misc/sigint-1.sh         f
+tests/misc/sigint-2.sh         f
+tests/misc/sigint-3.sh         f
+tests/misc/sigint-4.sh         f
+tests/misc/test-minus-e.1      f
+tests/misc/test-minus-e.2      f
+tests/misc/wait-bg.tests       f
+#examples/scripts.v2/PERMISSION        f
+#examples/scripts.v2/README    f
+#examples/scripts.v2/arc2tarz  f
+#examples/scripts.v2/bashrand  f
+#examples/scripts.v2/cal2day.bash      f
+#examples/scripts.v2/cdhist.bash       f
+#examples/scripts.v2/corename  f
+#examples/scripts.v2/fman      f
+#examples/scripts.v2/frcp      f
+#examples/scripts.v2/lowercase f
+#examples/scripts.v2/ncp       f
+#examples/scripts.v2/newext    f
+#examples/scripts.v2/nmv       f
+#examples/scripts.v2/pages     f
+#examples/scripts.v2/pf        f
+#examples/scripts.v2/ren               f
+#examples/scripts.v2/rename    f
+#examples/scripts.v2/repeat    f
+#examples/scripts.v2/untar     f
+#examples/scripts.v2/uudec     f
+#examples/scripts.v2/uuenc     f
+#examples/scripts.v2/vtree     f
+#examples/scripts.v2/where     f
+#examples/scripts.v2/pmtop     f
+#examples/scripts.v2/shprof    f
+#examples/scripts.noah/PERMISSION      f
+#examples/scripts.noah/README  f
+#examples/scripts.noah/aref.bash       f
+#examples/scripts.noah/bash.sub.bash   f
+#examples/scripts.noah/bash_version.bash       f
+#examples/scripts.noah/meta.bash       f
+#examples/scripts.noah/mktmp.bash      f
+#examples/scripts.noah/number.bash     f
+#examples/scripts.noah/prompt.bash     f
+#examples/scripts.noah/remap_keys.bash f
+#examples/scripts.noah/require.bash    f
+#examples/scripts.noah/send_mail.bash  f
+#examples/scripts.noah/shcat.bash      f
+#examples/scripts.noah/source.bash     f
+#examples/scripts.noah/string.bash     f
+#examples/scripts.noah/stty.bash       f
+#examples/scripts.noah/y_or_n_p.bash   f
index f420b6212a3e5c6708c6b30787727752912ff6a7..b8598fc70d1c8f2625e5591f4166b7749f76a09f 100644 (file)
@@ -312,12 +312,25 @@ parse_and_execute (string, from_file, flags)
            {
              struct fd_bitmap *bitmap;
 
-             if ((flags & SEVAL_FUNCDEF) && command->type != cm_function_def)
+             if (flags & SEVAL_FUNCDEF)
                {
-                 internal_warning ("%s: ignoring function definition attempt", from_file);
-                 should_jump_to_top_level = 0;
-                 last_result = last_command_exit_value = EX_BADUSAGE;
-                 break;
+                 char *x;
+
+                 /* If the command parses to something other than a straight
+                    function definition, or if we have not consumed the entire
+                    string, or if the parser has transformed the function
+                    name (as parsing will if it begins or ends with shell
+                    whitespace, for example), reject the attempt */
+                 if (command->type != cm_function_def ||
+                     ((x = parser_remaining_input ()) && *x) ||
+                     (STREQ (from_file, command->value.Function_def->name->word) == 0))
+                   {
+                     internal_warning (_("%s: ignoring function definition attempt"), from_file);
+                     should_jump_to_top_level = 0;
+                     last_result = last_command_exit_value = EX_BADUSAGE;
+                     reset_parser ();
+                     break;
+                   }
                }
 
              bitmap = new_fd_bitmap (FD_BITMAP_SIZE);
@@ -382,7 +395,10 @@ parse_and_execute (string, from_file, flags)
              discard_unwind_frame ("pe_dispose");
 
              if (flags & SEVAL_ONECMD)
-               break;
+               {
+                 reset_parser ();
+                 break;
+               }
            }
        }
       else
index 9b7f8522a2b9644e01e13940140abaf7c4f9cc78..a2233b1046f28c0bc646078239bfbb4f3044df58 100644 (file)
@@ -188,6 +188,11 @@ set_or_show_attributes (list, attribute, nodefs)
                  builtin_error (_("%s: not a function"), name);
                  any_failed++;
                }
+             else if ((attribute & att_exported) && undo == 0 && exportable_function_name (name) == 0)
+               {
+                 builtin_error (_("%s: cannot export"), name);
+                 any_failed++;
+               }
              else
                SETVARATTR (var, attribute, undo);
 
diff --git a/builtins/setattr.def~ b/builtins/setattr.def~
new file mode 100644 (file)
index 0000000..864617c
--- /dev/null
@@ -0,0 +1,560 @@
+This file is setattr.def, from which is created setattr.c.
+It implements the builtins "export" and "readonly", in Bash.
+
+Copyright (C) 1987-2012 Free Software Foundation, Inc.
+
+This file is part of GNU Bash, the Bourne Again SHell.
+
+Bash is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+Bash is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Bash.  If not, see <http://www.gnu.org/licenses/>.
+
+$PRODUCES setattr.c
+
+#include <config.h>
+
+#if defined (HAVE_UNISTD_H)
+#  ifdef _MINIX
+#    include <sys/types.h>
+#  endif
+#  include <unistd.h>
+#endif
+
+#include <stdio.h>
+#include "../bashansi.h"
+#include "../bashintl.h"
+
+#include "../shell.h"
+#include "../flags.h"
+#include "common.h"
+#include "bashgetopt.h"
+
+extern int posixly_correct;
+extern int array_needs_making;
+extern char *this_command_name;
+extern sh_builtin_func_t *this_shell_builtin;
+
+#ifdef ARRAY_VARS
+extern int declare_builtin __P((WORD_LIST *));
+#endif
+
+#define READONLY_OR_EXPORT \
+  (this_shell_builtin == readonly_builtin || this_shell_builtin == export_builtin)
+
+$BUILTIN export
+$FUNCTION export_builtin
+$SHORT_DOC export [-fn] [name[=value] ...] or export -p
+Set export attribute for shell variables.
+
+Marks each NAME for automatic export to the environment of subsequently
+executed commands.  If VALUE is supplied, assign VALUE before exporting.
+
+Options:
+  -f   refer to shell functions
+  -n   remove the export property from each NAME
+  -p   display a list of all exported variables and functions
+
+An argument of `--' disables further option processing.
+
+Exit Status:
+Returns success unless an invalid option is given or NAME is invalid.
+$END
+
+/* For each variable name in LIST, make that variable appear in the
+   environment passed to simple commands.  If there is no LIST, then
+   print all such variables.  An argument of `-n' says to remove the
+   exported attribute from variables named in LIST.  An argument of
+  -f indicates that the names present in LIST refer to functions. */
+int
+export_builtin (list)
+     register WORD_LIST *list;
+{
+  return (set_or_show_attributes (list, att_exported, 0));
+}
+
+$BUILTIN readonly
+$FUNCTION readonly_builtin
+$SHORT_DOC readonly [-aAf] [name[=value] ...] or readonly -p
+Mark shell variables as unchangeable.
+
+Mark each NAME as read-only; the values of these NAMEs may not be
+changed by subsequent assignment.  If VALUE is supplied, assign VALUE
+before marking as read-only.
+
+Options:
+  -a   refer to indexed array variables
+  -A   refer to associative array variables
+  -f   refer to shell functions
+  -p   display a list of all readonly variables or functions, depending on
+        whether or not the -f option is given
+
+An argument of `--' disables further option processing.
+
+Exit Status:
+Returns success unless an invalid option is given or NAME is invalid.
+$END
+
+/* For each variable name in LIST, make that variable readonly.  Given an
+   empty LIST, print out all existing readonly variables. */
+int
+readonly_builtin (list)
+     register WORD_LIST *list;
+{
+  return (set_or_show_attributes (list, att_readonly, 0));
+}
+
+#if defined (ARRAY_VARS)
+#  define ATTROPTS     "aAfnp"
+#else
+#  define ATTROPTS     "fnp"
+#endif
+
+/* For each variable name in LIST, make that variable have the specified
+   ATTRIBUTE.  An arg of `-n' says to remove the attribute from the the
+   remaining names in LIST (doesn't work for readonly). */
+int
+set_or_show_attributes (list, attribute, nodefs)
+     register WORD_LIST *list;
+     int attribute, nodefs;
+{
+  register SHELL_VAR *var;
+  int assign, undo, any_failed, assign_error, opt;
+  int functions_only, arrays_only, assoc_only;
+  int aflags;
+  char *name;
+#if defined (ARRAY_VARS)
+  WORD_LIST *nlist, *tlist;
+  WORD_DESC *w;
+#endif
+
+  functions_only = arrays_only = assoc_only = 0;
+  undo = any_failed = assign_error = 0;
+  /* Read arguments from the front of the list. */
+  reset_internal_getopt ();
+  while ((opt = internal_getopt (list, ATTROPTS)) != -1)
+    {
+      switch (opt)
+       {
+         case 'n':
+           undo = 1;
+           break;
+         case 'f':
+           functions_only = 1;
+           break;
+#if defined (ARRAY_VARS)
+         case 'a':
+           arrays_only = 1;
+           break;
+         case 'A':
+           assoc_only = 1;
+           break;
+#endif
+         case 'p':
+           break;
+         default:
+           builtin_usage ();
+           return (EX_USAGE);
+       }
+    }
+  list = loptend;
+
+  if (list)
+    {
+      if (attribute & att_exported)
+       array_needs_making = 1;
+
+      /* Cannot undo readonly status, silently disallowed. */
+      if (undo && (attribute & att_readonly))
+       attribute &= ~att_readonly;
+
+      while (list)
+       {
+         name = list->word->word;
+
+         if (functions_only)           /* xxx -f name */
+           {
+             var = find_function (name);
+             if (var == 0)
+               {
+                 builtin_error (_("%s: not a function"), name);
+                 any_failed++;
+               }
+             else if (exportable_function_name (name) == 0)
+               {
+                 builtin_error (_("%s: cannot export"), name);
+                 any_failed++;
+               }
+             else
+               SETVARATTR (var, attribute, undo);
+
+             list = list->next;
+             continue;
+           }
+
+         /* xxx [-np] name[=value] */
+         assign = assignment (name, 0);
+
+         aflags = 0;
+         if (assign)
+           {
+             name[assign] = '\0';
+             if (name[assign - 1] == '+')
+               {
+                 aflags |= ASS_APPEND;
+                 name[assign - 1] = '\0';
+               }
+           }
+
+         if (legal_identifier (name) == 0)
+           {
+             sh_invalidid (name);
+             if (assign)
+               assign_error++;
+             else
+               any_failed++;
+             list = list->next;
+             continue;
+           }
+
+         if (assign)   /* xxx [-np] name=value */
+           {
+             name[assign] = '=';
+             if (aflags & ASS_APPEND)
+               name[assign - 1] = '+';
+#if defined (ARRAY_VARS)
+             /* Let's try something here.  Turn readonly -a xxx=yyy into
+                declare -ra xxx=yyy and see what that gets us. */
+             if (arrays_only || assoc_only)
+               {
+                 tlist = list->next;
+                 list->next = (WORD_LIST *)NULL;
+                 w = arrays_only ? make_word ("-ra") : make_word ("-rA");
+                 nlist = make_word_list (w, list);
+                 opt = declare_builtin (nlist);
+                 if (opt != EXECUTION_SUCCESS)
+                   assign_error++;
+                 list->next = tlist;
+                 dispose_word (w);
+                 free (nlist);
+               }
+             else
+#endif
+             /* This word has already been expanded once with command
+                and parameter expansion.  Call do_assignment_no_expand (),
+                which does not do command or parameter substitution.  If
+                the assignment is not performed correctly, flag an error. */
+             if (do_assignment_no_expand (name) == 0)
+               assign_error++;
+             name[assign] = '\0';
+             if (aflags & ASS_APPEND)
+               name[assign - 1] = '\0';
+           }
+
+         set_var_attribute (name, attribute, undo);
+         list = list->next;
+       }
+    }
+  else
+    {
+      SHELL_VAR **variable_list;
+      register int i;
+
+      if ((attribute & att_function) || functions_only)
+       {
+         variable_list = all_shell_functions ();
+         if (attribute != att_function)
+           attribute &= ~att_function; /* so declare -xf works, for example */
+       }
+      else
+       variable_list = all_shell_variables ();
+
+#if defined (ARRAY_VARS)
+      if (attribute & att_array)
+       {
+         arrays_only++;
+         if (attribute != att_array)
+           attribute &= ~att_array;
+       }
+      else if (attribute & att_assoc)
+       {
+         assoc_only++;
+         if (attribute != att_assoc)
+           attribute &= ~att_assoc;
+       }
+#endif
+
+      if (variable_list)
+       {
+         for (i = 0; var = variable_list[i]; i++)
+           {
+#if defined (ARRAY_VARS)
+             if (arrays_only && array_p (var) == 0)
+               continue;
+             else if (assoc_only && assoc_p (var) == 0)
+               continue;
+#endif
+             if ((var->attributes & attribute))
+               {
+                 show_var_attributes (var, READONLY_OR_EXPORT, nodefs);
+                 if (any_failed = sh_chkwrite (any_failed))
+                   break;
+               }
+           }
+         free (variable_list);
+       }
+    }
+
+  return (assign_error ? EX_BADASSIGN
+                      : ((any_failed == 0) ? EXECUTION_SUCCESS
+                                           : EXECUTION_FAILURE));
+}
+
+/* Show all variable variables (v == 1) or functions (v == 0) with
+   attributes. */
+int
+show_all_var_attributes (v, nodefs)
+     int v, nodefs;
+{
+  SHELL_VAR **variable_list, *var;
+  int any_failed;
+  register int i;
+
+  variable_list = v ? all_shell_variables () : all_shell_functions ();
+  if (variable_list == 0)  
+    return (EXECUTION_SUCCESS);
+
+  for (i = any_failed = 0; var = variable_list[i]; i++)
+    {
+      show_var_attributes (var, READONLY_OR_EXPORT, nodefs);
+      if (any_failed = sh_chkwrite (any_failed))
+        break;
+    }
+  free (variable_list);
+  return (any_failed == 0 ? EXECUTION_SUCCESS : EXECUTION_FAILURE);
+}
+
+/* Show the attributes for shell variable VAR.  If NODEFS is non-zero,
+   don't show function definitions along with the name.  If PATTR is
+   non-zero, it indicates we're being called from `export' or `readonly'.
+   In POSIX mode, this prints the name of the calling builtin (`export'
+   or `readonly') instead of `declare', and doesn't print function defs
+   when called by `export' or `readonly'. */
+int
+show_var_attributes (var, pattr, nodefs)
+     SHELL_VAR *var;
+     int pattr, nodefs;
+{
+  char flags[16], *x;
+  int i;
+
+  i = 0;
+
+  /* pattr == 0 means we are called from `declare'. */
+  if (pattr == 0 || posixly_correct == 0)
+    {
+#if defined (ARRAY_VARS)
+      if (array_p (var))
+       flags[i++] = 'a';
+
+      if (assoc_p (var))
+       flags[i++] = 'A';
+#endif
+
+      if (function_p (var))
+       flags[i++] = 'f';
+
+      if (integer_p (var))
+       flags[i++] = 'i';
+
+      if (nameref_p (var))
+       flags[i++] = 'n';
+
+      if (readonly_p (var))
+       flags[i++] = 'r';
+
+      if (trace_p (var))
+       flags[i++] = 't';
+
+      if (exported_p (var))
+       flags[i++] = 'x';
+
+      if (capcase_p (var))
+       flags[i++] = 'c';
+
+      if (lowercase_p (var))
+       flags[i++] = 'l';
+
+      if (uppercase_p (var))
+       flags[i++] = 'u';
+    }
+  else
+    {
+#if defined (ARRAY_VARS)
+      if (array_p (var))
+       flags[i++] = 'a';
+
+      if (assoc_p (var))
+       flags[i++] = 'A';
+#endif
+
+      if (function_p (var))
+       flags[i++] = 'f';
+    }
+
+  flags[i] = '\0';
+
+  /* If we're printing functions with definitions, print the function def
+     first, then the attributes, instead of printing output that can't be
+     reused as input to recreate the current state. */
+  if (function_p (var) && nodefs == 0 && (pattr == 0 || posixly_correct == 0))
+    {
+      printf ("%s\n", named_function_string (var->name, function_cell (var), FUNC_MULTILINE|FUNC_EXTERNAL));
+      nodefs++;
+      if (pattr == 0 && i == 1 && flags[0] == 'f')
+       return 0;               /* don't print `declare -f name' */
+    }
+
+  if (pattr == 0 || posixly_correct == 0)
+    printf ("declare -%s ", i ? flags : "-");
+  else if (i)
+    printf ("%s -%s ", this_command_name, flags);
+  else
+    printf ("%s ", this_command_name);
+
+#if defined (ARRAY_VARS)
+  if (invisible_p (var) && (array_p (var) || assoc_p (var)))
+    printf ("%s\n", var->name);
+  else if (array_p (var))
+    print_array_assignment (var, 1);
+  else if (assoc_p (var))
+    print_assoc_assignment (var, 1);
+  else
+#endif
+  /* force `readonly' and `export' to not print out function definitions
+     when in POSIX mode. */
+  if (nodefs || (function_p (var) && pattr != 0 && posixly_correct))
+    printf ("%s\n", var->name);
+  else if (function_p (var))
+    printf ("%s\n", named_function_string (var->name, function_cell (var), FUNC_MULTILINE|FUNC_EXTERNAL));
+  else if (invisible_p (var) || var_isset (var) == 0)
+    printf ("%s\n", var->name);
+  else
+    {
+      x = sh_double_quote (value_cell (var));
+      printf ("%s=%s\n", var->name, x);
+      free (x);
+    }
+  return (0);
+}
+
+int
+show_name_attributes (name, nodefs)
+     char *name;
+     int nodefs;
+{
+  SHELL_VAR *var;
+
+#if 0
+  var = find_variable_tempenv (name);
+#else
+  var = find_variable_noref (name);
+#endif
+
+  if (var /* && invisible_p (var) == 0 */)     /* XXX bash-4.4/bash-5.0 */
+    {
+      show_var_attributes (var, READONLY_OR_EXPORT, nodefs);
+      return (0);
+    }
+  else
+    return (1);
+}
+
+int
+show_func_attributes (name, nodefs)
+     char *name;
+     int nodefs;
+{
+  SHELL_VAR *var;
+
+  var = find_function (name);
+
+  if (var)
+    {
+      show_var_attributes (var, READONLY_OR_EXPORT, nodefs);
+      return (0);
+    }
+  else
+    return (1);
+}
+
+void
+set_var_attribute (name, attribute, undo)
+     char *name;
+     int attribute, undo;
+{
+  SHELL_VAR *var, *tv, *v;
+  char *tvalue;
+
+  if (undo)
+    var = find_variable (name);
+  else
+    {
+      tv = find_tempenv_variable (name);
+      /* XXX -- need to handle case where tv is a temp variable in a
+        function-scope context, since function_env has been merged into
+        the local variables table. */
+      if (tv && tempvar_p (tv))
+       {
+         tvalue = var_isset (tv) ? savestring (value_cell (tv)) : savestring ("");
+
+         var = bind_variable (tv->name, tvalue, 0);
+         var->attributes |= tv->attributes & ~att_tempvar;
+         /* This avoids an error message when propagating a read-only var
+            later on. */
+         if (var->context == 0 && (attribute & att_readonly))
+           {
+             /* Don't bother to set the `propagate to the global variables
+                table' flag if we've just bound the variable in that table */
+             v = find_global_variable (tv->name);
+             if (v != var)
+               VSETATTR (tv, att_propagate);
+           }
+         else
+           VSETATTR (tv, att_propagate);
+         if (var->context != 0)
+           VSETATTR (var, att_propagate);
+         SETVARATTR (tv, attribute, undo);     /* XXX */
+
+         stupidly_hack_special_variables (tv->name);
+
+         free (tvalue);
+       }
+      else
+       {
+         var = find_variable_notempenv (name);
+         if (var == 0)
+           {
+             var = bind_variable (name, (char *)NULL, 0);
+             if (no_invisible_vars == 0)
+               VSETATTR (var, att_invisible);
+           }
+         else if (var->context != 0)
+           VSETATTR (var, att_propagate);
+       }
+    }
+
+  if (var)
+    SETVARATTR (var, attribute, undo);
+
+  if (var && (exported_p (var) || (attribute & att_exported)))
+    array_needs_making++;      /* XXX */
+}
index b806ef05720a4c3d6126425332f1f9f7acdadc33..5707f8ba78abcac51bc05de2137ac9ac1ac9047c 100644 (file)
@@ -459,7 +459,7 @@ char        **argv;
 void
 builtin_usage()
 {
-       fprintf(stderr, "%s: usage: %s [-%s] [file ...]\n", prog, OPTIONS);
+       fprintf(stderr, "%s: usage: %s [-%s] [file ...]\n", prog, prog, OPTIONS);
 }
 
 #ifndef HAVE_STRERROR
index 52820d19f0f53000fd3d2c4b1792307fdce0cc7a..d351eb3cd98c3d453824ac3ccf6f56a12b57e85a 100644 (file)
--- a/general.c
+++ b/general.c
@@ -245,15 +245,36 @@ check_identifier (word, check_word)
     return (1);
 }
 
+/* Return 1 if STRING is a function name that the shell will import from
+   the environment.  Currently we reject attempts to import shell functions
+   containing slashes, beginning with newlines or containing blanks.  In
+   Posix mode, we require that STRING be a valid shell identifier.  Not
+   used yet. */
 int
-legal_function_name (string)
+importable_function_name (string, len)
      char *string;
+     size_t len;
 {
   if (absolute_program (string))       /* don't allow slash */
     return 0;
+  if (*string == '\n')                 /* can't start with a newline */
+    return 0;
+  if (shellblank (*string) || shellblank(string[len-1]))
+    return 0;
   return (posixly_correct ? legal_identifier (string) : 1);
 }
 
+int
+exportable_function_name (string)
+     char *string;
+{
+  if (absolute_program (string))
+    return 0;
+  if (mbschr (string, '=') != 0)
+    return 0;
+  return 1;
+}
+
 /* Return 1 if STRING comprises a valid alias name.  The shell accepts
    essentially all characters except those which must be quoted to the
    parser (which disqualifies them from alias expansion anyway) and `/'. */
index 324a05a6f893f4df5e4681484d533eaf34cca874..57ee54734fe4eb9b6ec4546eabb849db3e89b691 100644 (file)
@@ -53,6 +53,7 @@ extern int interactive_comments;
 extern int check_hashed_filenames;
 extern int source_uses_path;
 extern int source_searches_cwd;
+extern int posixly_correct;
 
 static char *bash_special_tilde_expansions __P((char *));
 static int unquoted_tilde_word __P((const char *));
@@ -244,15 +245,36 @@ check_identifier (word, check_word)
     return (1);
 }
 
+/* Return 1 if STRING is a function name that the shell will import from
+   the environment.  Currently we reject attempts to import shell functions
+   containing slashes, beginning with newlines or containing blanks.  In
+   Posix mode, we require that STRING be a valid shell identifier.  Not
+   used yet. */
 int
-legal_function_name (string)
+importable_function_name (string, len)
      char *string;
+     size_t len;
 {
   if (absolute_program (string))       /* don't allow slash */
     return 0;
+  if (*string == '\n')                 /* can't start with a newline */
+    return 0;
+  if (shellblank (*string) || shellblank(string[len-1]))
+    return 0;
   return (posixly_correct ? legal_identifier (string) : 1);
 }
 
+int
+exportable_function_name (string)
+     char *string;
+{
+  if (absolute_program (name))
+    return 0;
+  if (mbschr (string, '=') != 0)
+    return 0;
+  return 1;
+}
+
 /* Return 1 if STRING comprises a valid alias name.  The shell accepts
    essentially all characters except those which must be quoted to the
    parser (which disqualifies them from alias expansion anyway) and `/'. */
index 65d55c9bf42a9bf8fe9f88cf8ed449f26a83b87b..e252af569641eed835e2f837f0f82521266615ba 100644 (file)
--- a/general.h
+++ b/general.h
@@ -283,7 +283,8 @@ extern void print_rlimtype __P((RLIMTYPE, int));
 extern int all_digits __P((char *));
 extern int legal_number __P((const char *, intmax_t *));
 extern int legal_identifier __P((char *));
-extern int legal_function_name __P((char *));
+extern int importable_function_name __P((char *, size_t));
+extern int exportable_function_name __P((char *));
 extern int check_identifier __P((WORD_DESC *, int));
 extern int legal_alias_name __P((char *, int));
 extern int assignment __P((const char *, int));
index 97baf22bb1b2d15e5bc8771e31468304f2b3010f..fc313e6c665b3e4be0360d1deebb852be4041bf1 100644 (file)
@@ -283,6 +283,7 @@ extern void print_rlimtype __P((RLIMTYPE, int));
 extern int all_digits __P((char *));
 extern int legal_number __P((const char *, intmax_t *));
 extern int legal_identifier __P((char *));
+extern int importable_function_name __P((char *, size_t));
 extern int check_identifier __P((WORD_DESC *, int));
 extern int legal_alias_name __P((char *, int));
 extern int assignment __P((const char *, int));
diff --git a/jobs.c b/jobs.c
index e5241342ef6a132d41adb5f62a171340af03ad42..f895ff6e316eda57fee1901df1be0883a7da7c2f 100644 (file)
--- a/jobs.c
+++ b/jobs.c
@@ -772,6 +772,9 @@ bgp_prune ()
 {
   struct pidstat *ps;
 
+  if (bgpids.npid == 0 || bgpids.list == 0)
+    return;            /* just paranoia */
+
   while (bgpids.npid > js.c_childmax)
     {
       ps = bgpids.list;
diff --git a/parse.y b/parse.y
index 0db867d182a1d230a6338f0502124ba9a482ad7c..cf874a9a45bedb88aff0ffe7d6c30244b3a96d79 100644 (file)
--- a/parse.y
+++ b/parse.y
@@ -2538,6 +2538,16 @@ shell_ungetc (c)
     eol_ungetc_lookahead = c;
 }
 
+char *
+parser_remaining_input ()
+{
+  if (shell_input_line == 0)
+    return 0;
+  if (shell_input_line_index < 0 || shell_input_line_index >= shell_input_line_len)
+    return '\0';       /* XXX */
+  return (shell_input_line + shell_input_line_index);
+}
+
 #ifdef INCLUDE_UNUSED
 /* Back the input pointer up by one, effectively `ungetting' a character. */
 static void
@@ -4034,6 +4044,7 @@ xparse_dolparen (base, string, indp, flags)
   /*(*/
   parser_state |= PST_CMDSUBST|PST_EOFTOKEN;   /* allow instant ')' */ /*(*/
   shell_eof_token = ')';
+
   parse_string (string, "command substitution", sflags, &ep);
 
   shell_eof_token = orig_eof_token;
@@ -4041,8 +4052,8 @@ xparse_dolparen (base, string, indp, flags)
   reset_parser ();
   /* reset_parser clears shell_input_line and associated variables */
   restore_input_line_state (&ls);
-  if (interactive)
-    token_to_read = 0;
+
+  token_to_read = 0;
 
   /* Need to find how many characters parse_and_execute consumed, update
      *indp, if flags != 0, copy the portion of the string parsed into RET
index e987c5701111f4121a02a18730b2f91bd894120d..96c13b39e948a151ea8fbfe901ed0513bfcb50f0 100644 (file)
@@ -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 25
+#define PATCHLEVEL 28
 
 #endif /* _PATCHLEVEL_H_ */
index ea63dca46d942d9cdef1e64b8fbe25f4c0cb1c8f..000118ac60322faf4920aa68317b0ea799ba3cd4 100644 (file)
@@ -51,6 +51,7 @@ extern int printf __P((const char *, ...));   /* Yuck.  Double yuck. */
 #endif
 
 extern int indirection_level;
+extern int posixly_correct;
 
 static int indentation;
 static int indentation_amount = 4;
@@ -1275,7 +1276,11 @@ print_function_def (func)
   REDIRECT *func_redirects;
 
   func_redirects = NULL;
-  cprintf ("function %s () \n", func->name->word);
+  /* When in posix mode, print functions as posix specifies them. */
+  if (posixly_correct == 0)
+    cprintf ("function %s () \n", func->name->word);
+  else
+    cprintf ("%s () \n", func->name->word);
   add_unwind_protect (reset_locals, 0);
 
   indent (indentation);
diff --git a/print_cmd.c~ b/print_cmd.c~
new file mode 100644 (file)
index 0000000..39c411f
--- /dev/null
@@ -0,0 +1,1595 @@
+/* print_command -- A way to make readable commands from a command tree. */
+
+/* Copyright (C) 1989-2011 Free Software Foundation, Inc.
+
+   This file is part of GNU Bash, the Bourne Again SHell.
+
+   Bash is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
+
+   Bash is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with Bash.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "config.h"
+
+#include <stdio.h>
+
+#if defined (HAVE_UNISTD_H)
+#  ifdef _MINIX
+#    include <sys/types.h>
+#  endif
+#  include <unistd.h>
+#endif
+
+#if defined (PREFER_STDARG)
+#  include <stdarg.h>
+#else
+#  include <varargs.h>
+#endif
+
+#include "bashansi.h"
+#include "bashintl.h"
+
+#include "shell.h"
+#include "flags.h"
+#include <y.tab.h>     /* use <...> so we pick it up from the build directory */
+
+#include "shmbutil.h"
+
+#include "builtins/common.h"
+
+#if !HAVE_DECL_PRINTF
+extern int printf __P((const char *, ...));    /* Yuck.  Double yuck. */
+#endif
+
+extern int indirection_level;
+
+static int indentation;
+static int indentation_amount = 4;
+
+#if defined (PREFER_STDARG)
+typedef void PFUNC __P((const char *, ...));
+
+static void cprintf __P((const char *, ...))  __attribute__((__format__ (printf, 1, 2)));
+static void xprintf __P((const char *, ...))  __attribute__((__format__ (printf, 1, 2)));
+#else
+#define PFUNC VFunction
+static void cprintf ();
+static void xprintf ();
+#endif
+
+static void reset_locals __P((void));
+static void newline __P((char *));
+static void indent __P((int));
+static void semicolon __P((void));
+static void the_printed_command_resize __P((int));
+
+static void make_command_string_internal __P((COMMAND *));
+static void _print_word_list __P((WORD_LIST *, char *, PFUNC *));
+static void command_print_word_list __P((WORD_LIST *, char *));
+static void print_case_clauses __P((PATTERN_LIST *));
+static void print_redirection_list __P((REDIRECT *));
+static void print_redirection __P((REDIRECT *));
+static void print_heredoc_header __P((REDIRECT *));
+static void print_heredoc_body __P((REDIRECT *));
+static void print_heredocs __P((REDIRECT *));
+static void print_deferred_heredocs __P((const char *));
+
+static void print_for_command __P((FOR_COM *));
+#if defined (ARITH_FOR_COMMAND)
+static void print_arith_for_command __P((ARITH_FOR_COM *));
+#endif
+#if defined (SELECT_COMMAND)
+static void print_select_command __P((SELECT_COM *));
+#endif
+static void print_group_command __P((GROUP_COM *));
+static void print_case_command __P((CASE_COM *));
+static void print_while_command __P((WHILE_COM *));
+static void print_until_command __P((WHILE_COM *));
+static void print_until_or_while __P((WHILE_COM *, char *));
+static void print_if_command __P((IF_COM *));
+#if defined (COND_COMMAND)
+static void print_cond_node __P((COND_COM *));
+#endif
+static void print_function_def __P((FUNCTION_DEF *));
+
+#define PRINTED_COMMAND_INITIAL_SIZE 64
+#define PRINTED_COMMAND_GROW_SIZE 128
+
+char *the_printed_command = (char *)NULL;
+int the_printed_command_size = 0;
+int command_string_index = 0;
+
+int xtrace_fd = -1;
+FILE *xtrace_fp = 0;
+
+#define CHECK_XTRACE_FP        xtrace_fp = (xtrace_fp ? xtrace_fp : stderr)
+
+/* shell expansion characters: used in print_redirection_list */
+#define EXPCHAR(c) ((c) == '{' || (c) == '~' || (c) == '$' || (c) == '`')
+
+#define PRINT_DEFERRED_HEREDOCS(x) \
+  do { \
+    if (deferred_heredocs) \
+      print_deferred_heredocs (x); \
+  } while (0)
+
+/* Non-zero means the stuff being printed is inside of a function def. */
+static int inside_function_def;
+static int skip_this_indent;
+static int was_heredoc;
+static int printing_connection;
+static REDIRECT *deferred_heredocs;
+
+/* The depth of the group commands that we are currently printing.  This
+   includes the group command that is a function body. */
+static int group_command_nesting;
+
+/* A buffer to indicate the indirection level (PS4) when set -x is enabled. */
+static char *indirection_string = 0;
+static int indirection_stringsiz = 0;
+
+/* Print COMMAND (a command tree) on standard output. */
+void
+print_command (command)
+     COMMAND *command;
+{
+  command_string_index = 0;
+  printf ("%s", make_command_string (command));
+}
+
+/* Make a string which is the printed representation of the command
+   tree in COMMAND.  We return this string.  However, the string is
+   not consed, so you have to do that yourself if you want it to
+   remain around. */
+char *
+make_command_string (command)
+     COMMAND *command;
+{
+  command_string_index = was_heredoc = 0;
+  deferred_heredocs = 0;
+  make_command_string_internal (command);
+  return (the_printed_command);
+}
+
+/* The internal function.  This is the real workhorse. */
+static void
+make_command_string_internal (command)
+     COMMAND *command;
+{
+  char s[3];
+
+  if (command == 0)
+    cprintf ("");
+  else
+    {
+      if (skip_this_indent)
+       skip_this_indent--;
+      else
+       indent (indentation);
+
+      if (command->flags & CMD_TIME_PIPELINE)
+       {
+         cprintf ("time ");
+         if (command->flags & CMD_TIME_POSIX)
+           cprintf ("-p ");
+       }
+
+      if (command->flags & CMD_INVERT_RETURN)
+       cprintf ("! ");
+
+      switch (command->type)
+       {
+       case cm_for:
+         print_for_command (command->value.For);
+         break;
+
+#if defined (ARITH_FOR_COMMAND)
+       case cm_arith_for:
+         print_arith_for_command (command->value.ArithFor);
+         break;
+#endif
+
+#if defined (SELECT_COMMAND)
+       case cm_select:
+         print_select_command (command->value.Select);
+         break;
+#endif
+
+       case cm_case:
+         print_case_command (command->value.Case);
+         break;
+
+       case cm_while:
+         print_while_command (command->value.While);
+         break;
+
+       case cm_until:
+         print_until_command (command->value.While);
+         break;
+
+       case cm_if:
+         print_if_command (command->value.If);
+         break;
+
+#if defined (DPAREN_ARITHMETIC)
+       case cm_arith:
+         print_arith_command (command->value.Arith->exp);
+         break;
+#endif
+
+#if defined (COND_COMMAND)
+       case cm_cond:
+         print_cond_command (command->value.Cond);
+         break;
+#endif
+
+       case cm_simple:
+         print_simple_command (command->value.Simple);
+         break;
+
+       case cm_connection:
+
+         skip_this_indent++;
+         printing_connection++;
+         make_command_string_internal (command->value.Connection->first);
+
+         switch (command->value.Connection->connector)
+           {
+           case '&':
+           case '|':
+             {
+               char c = command->value.Connection->connector;
+
+               s[0] = ' ';
+               s[1] = c;
+               s[2] = '\0';
+               
+               print_deferred_heredocs (s);
+
+               if (c != '&' || command->value.Connection->second)
+                 {
+                   cprintf (" ");
+                   skip_this_indent++;
+                 }
+             }
+             break;
+
+           case AND_AND:
+             print_deferred_heredocs (" && ");
+             if (command->value.Connection->second)
+               skip_this_indent++;
+             break;
+
+           case OR_OR:
+             print_deferred_heredocs (" || ");
+             if (command->value.Connection->second)
+               skip_this_indent++;
+             break;
+
+           case ';':
+             if (deferred_heredocs == 0)
+               {
+                 if (was_heredoc == 0)
+                   cprintf (";");
+                 else
+                   was_heredoc = 0;
+               }
+             else
+               print_deferred_heredocs (inside_function_def ? "" : ";");
+
+             if (inside_function_def)
+               cprintf ("\n");
+             else
+               {
+                 cprintf (" ");
+                 if (command->value.Connection->second)
+                   skip_this_indent++;
+               }
+             break;
+
+           default:
+             cprintf (_("print_command: bad connector `%d'"),
+                      command->value.Connection->connector);
+             break;
+           }
+
+         make_command_string_internal (command->value.Connection->second);
+         PRINT_DEFERRED_HEREDOCS ("");
+         printing_connection--;                  
+         break;
+
+       case cm_function_def:
+         print_function_def (command->value.Function_def);
+         break;
+
+       case cm_group:
+         print_group_command (command->value.Group);
+         break;
+
+       case cm_subshell:
+         cprintf ("( ");
+         skip_this_indent++;
+         make_command_string_internal (command->value.Subshell->command);
+         PRINT_DEFERRED_HEREDOCS ("");
+         cprintf (" )");
+         break;
+
+       case cm_coproc:
+         cprintf ("coproc %s ", command->value.Coproc->name);
+         skip_this_indent++;
+         make_command_string_internal (command->value.Coproc->command);
+         break;
+
+       default:
+         command_error ("print_command", CMDERR_BADTYPE, command->type, 0);
+         break;
+       }
+
+
+      if (command->redirects)
+       {
+         cprintf (" ");
+         print_redirection_list (command->redirects);
+       }
+    }
+}
+
+static void
+_print_word_list (list, separator, pfunc)
+     WORD_LIST *list;
+     char *separator;
+     PFUNC *pfunc;
+{
+  WORD_LIST *w;
+
+  for (w = list; w; w = w->next)
+    (*pfunc) ("%s%s", w->word->word, w->next ? separator : "");
+}
+
+void
+print_word_list (list, separator)
+     WORD_LIST *list;
+     char *separator;
+{
+  _print_word_list (list, separator, xprintf);
+}
+
+void
+xtrace_set (fd, fp)
+     int fd;
+     FILE *fp;
+{
+  if (fd >= 0 && sh_validfd (fd) == 0)
+    {
+      internal_error (_("xtrace_set: %d: invalid file descriptor"), fd);
+      return;
+    }
+  if (fp == 0)
+    {
+      internal_error (_("xtrace_set: NULL file pointer"));
+      return;
+    }
+  if (fd >= 0 && fileno (fp) != fd)
+    internal_warning (_("xtrace fd (%d) != fileno xtrace fp (%d)"), fd, fileno (fp));
+  
+  xtrace_fd = fd;
+  xtrace_fp = fp;
+}
+
+void
+xtrace_init ()
+{
+  xtrace_set (-1, stderr);
+}
+
+void
+xtrace_reset ()
+{
+  if (xtrace_fd >= 0 && xtrace_fp)
+    {
+      fflush (xtrace_fp);
+      fclose (xtrace_fp);
+    }
+  else if (xtrace_fd >= 0)
+    close (xtrace_fd);
+
+  xtrace_fd = -1;
+  xtrace_fp = stderr;
+}
+
+void
+xtrace_fdchk (fd)
+     int fd;
+{
+  if (fd == xtrace_fd)
+    xtrace_reset ();
+}
+
+/* Return a string denoting what our indirection level is. */
+
+char *
+indirection_level_string ()
+{
+  register int i, j;
+  char *ps4;
+  char ps4_firstc[MB_LEN_MAX+1];
+  int ps4_firstc_len, ps4_len, ineed, old;
+
+  ps4 = get_string_value ("PS4");
+  if (indirection_string == 0)
+    indirection_string = xmalloc (indirection_stringsiz = 100);
+  indirection_string[0] = '\0';
+
+  if (ps4 == 0 || *ps4 == '\0')
+    return (indirection_string);
+
+  old = change_flag ('x', FLAG_OFF);
+  ps4 = decode_prompt_string (ps4);
+  if (old)
+    change_flag ('x', FLAG_ON);
+
+  if (ps4 == 0 || *ps4 == '\0')
+    return (indirection_string);
+
+#if defined (HANDLE_MULTIBYTE)
+  ps4_len = strnlen (ps4, MB_CUR_MAX);
+  ps4_firstc_len = MBLEN (ps4, ps4_len);
+  if (ps4_firstc_len == 1 || ps4_firstc_len == 0 || ps4_firstc_len < 0)
+    {
+      ps4_firstc[0] = ps4[0];
+      ps4_firstc[ps4_firstc_len = 1] = '\0';
+    }
+  else
+    memcpy (ps4_firstc, ps4, ps4_firstc_len);
+#else
+  ps4_firstc[0] = ps4[0];
+  ps4_firstc[ps4_firstc_len = 1] = '\0';
+#endif
+
+  /* Dynamically resize indirection_string so we have room for everything
+     and we don't have to truncate ps4 */
+  ineed = (ps4_firstc_len * indirection_level) + strlen (ps4);
+  if (ineed > indirection_stringsiz - 1)
+    {
+      indirection_stringsiz = ineed + 1;
+      indirection_string = xrealloc (indirection_string, indirection_stringsiz);
+    }
+
+  for (i = j = 0; ps4_firstc[0] && j < indirection_level && i < indirection_stringsiz - 1; i += ps4_firstc_len, j++)
+    {
+      if (ps4_firstc_len == 1)
+       indirection_string[i] = ps4_firstc[0];
+      else
+       memcpy (indirection_string+i, ps4_firstc, ps4_firstc_len);
+    }      
+
+  for (j = ps4_firstc_len; *ps4 && ps4[j] && i < indirection_stringsiz - 1; i++, j++)
+    indirection_string[i] = ps4[j];
+
+  indirection_string[i] = '\0';
+  free (ps4);
+  return (indirection_string);
+}
+
+void
+xtrace_print_assignment (name, value, assign_list, xflags)
+     char *name, *value;
+     int assign_list, xflags;
+{
+  char *nval;
+
+  CHECK_XTRACE_FP;
+
+  if (xflags)
+    fprintf (xtrace_fp, "%s", indirection_level_string ());
+
+  /* VALUE should not be NULL when this is called. */
+  if (*value == '\0' || assign_list)
+    nval = value;
+  else if (sh_contains_shell_metas (value))
+    nval = sh_single_quote (value);
+  else if (ansic_shouldquote (value))
+    nval = ansic_quote (value, 0, (int *)0);
+  else
+    nval = value;
+
+  if (assign_list)
+    fprintf (xtrace_fp, "%s=(%s)\n", name, nval);
+  else
+    fprintf (xtrace_fp, "%s=%s\n", name, nval);
+
+  if (nval != value)
+    FREE (nval);
+
+  fflush (xtrace_fp);
+}
+
+/* A function to print the words of a simple command when set -x is on. */
+void
+xtrace_print_word_list (list, xtflags)
+     WORD_LIST *list;
+     int xtflags;
+{
+  WORD_LIST *w;
+  char *t, *x;
+
+  CHECK_XTRACE_FP;
+
+  if (xtflags)
+    fprintf (xtrace_fp, "%s", indirection_level_string ());
+
+  for (w = list; w; w = w->next)
+    {
+      t = w->word->word;
+      if (t == 0 || *t == '\0')
+       fprintf (xtrace_fp, "''%s", w->next ? " " : "");
+      else if (sh_contains_shell_metas (t))
+       {
+         x = sh_single_quote (t);
+         fprintf (xtrace_fp, "%s%s", x, w->next ? " " : "");
+         free (x);
+       }
+      else if (ansic_shouldquote (t))
+       {
+         x = ansic_quote (t, 0, (int *)0);
+         fprintf (xtrace_fp, "%s%s", x, w->next ? " " : "");
+         free (x);
+       }
+      else
+       fprintf (xtrace_fp, "%s%s", t, w->next ? " " : "");
+    }
+  fprintf (xtrace_fp, "\n");
+  fflush (xtrace_fp);
+}
+
+static void
+command_print_word_list (list, separator)
+     WORD_LIST *list;
+     char *separator;
+{
+  _print_word_list (list, separator, cprintf);
+}
+
+void
+print_for_command_head (for_command)
+     FOR_COM *for_command;
+{
+  cprintf ("for %s in ", for_command->name->word);
+  command_print_word_list (for_command->map_list, " ");
+}
+
+void
+xtrace_print_for_command_head (for_command)
+     FOR_COM *for_command;
+{
+  CHECK_XTRACE_FP;
+  fprintf (xtrace_fp, "%s", indirection_level_string ());
+  fprintf (xtrace_fp, "for %s in ", for_command->name->word);
+  xtrace_print_word_list (for_command->map_list, 0);
+}
+
+static void
+print_for_command (for_command)
+     FOR_COM *for_command;
+{
+  print_for_command_head (for_command);
+  cprintf (";");
+  newline ("do\n");
+
+  indentation += indentation_amount;
+  make_command_string_internal (for_command->action);
+  PRINT_DEFERRED_HEREDOCS ("");
+  semicolon ();
+  indentation -= indentation_amount;
+
+  newline ("done");
+}
+
+#if defined (ARITH_FOR_COMMAND)
+static void
+print_arith_for_command (arith_for_command)
+     ARITH_FOR_COM *arith_for_command;
+{
+  cprintf ("for ((");
+  command_print_word_list (arith_for_command->init, " ");
+  cprintf ("; ");
+  command_print_word_list (arith_for_command->test, " ");
+  cprintf ("; ");
+  command_print_word_list (arith_for_command->step, " ");
+  cprintf ("))");
+  newline ("do\n");
+  indentation += indentation_amount;
+  make_command_string_internal (arith_for_command->action);
+  PRINT_DEFERRED_HEREDOCS ("");
+  semicolon ();
+  indentation -= indentation_amount;
+  newline ("done");
+}
+#endif /* ARITH_FOR_COMMAND */
+
+#if defined (SELECT_COMMAND)
+void
+print_select_command_head (select_command)
+     SELECT_COM *select_command;
+{
+  cprintf ("select %s in ", select_command->name->word);
+  command_print_word_list (select_command->map_list, " ");
+}
+
+void
+xtrace_print_select_command_head (select_command)
+     SELECT_COM *select_command;
+{
+  CHECK_XTRACE_FP;
+  fprintf (xtrace_fp, "%s", indirection_level_string ());
+  fprintf (xtrace_fp, "select %s in ", select_command->name->word);
+  xtrace_print_word_list (select_command->map_list, 0);
+}
+
+static void
+print_select_command (select_command)
+     SELECT_COM *select_command;
+{
+  print_select_command_head (select_command);
+
+  cprintf (";");
+  newline ("do\n");
+  indentation += indentation_amount;
+  make_command_string_internal (select_command->action);
+  PRINT_DEFERRED_HEREDOCS ("");
+  semicolon ();
+  indentation -= indentation_amount;
+  newline ("done");
+}
+#endif /* SELECT_COMMAND */
+
+static void
+print_group_command (group_command)
+     GROUP_COM *group_command;
+{
+  group_command_nesting++;
+  cprintf ("{ ");
+
+  if (inside_function_def == 0)
+    skip_this_indent++;
+  else
+    {
+      /* This is a group command { ... } inside of a function
+        definition, and should be printed as a multiline group
+        command, using the current indentation. */
+      cprintf ("\n");
+      indentation += indentation_amount;
+    }
+
+  make_command_string_internal (group_command->command);
+  PRINT_DEFERRED_HEREDOCS ("");
+
+  if (inside_function_def)
+    {
+      cprintf ("\n");
+      indentation -= indentation_amount;
+      indent (indentation);
+    }
+  else
+    {
+      semicolon ();
+      cprintf (" ");
+    }
+
+  cprintf ("}");
+
+  group_command_nesting--;
+}
+
+void
+print_case_command_head (case_command)
+     CASE_COM *case_command;
+{
+  cprintf ("case %s in ", case_command->word->word);
+}
+
+void
+xtrace_print_case_command_head (case_command)
+     CASE_COM *case_command;
+{
+  CHECK_XTRACE_FP;
+  fprintf (xtrace_fp, "%s", indirection_level_string ());
+  fprintf (xtrace_fp, "case %s in\n", case_command->word->word);
+}
+
+static void
+print_case_command (case_command)
+     CASE_COM *case_command;
+{
+  print_case_command_head (case_command);
+
+  if (case_command->clauses)
+    print_case_clauses (case_command->clauses);
+  newline ("esac");
+}
+
+static void
+print_case_clauses (clauses)
+     PATTERN_LIST *clauses;
+{
+  indentation += indentation_amount;
+  while (clauses)
+    {
+      newline ("");
+      command_print_word_list (clauses->patterns, " | ");
+      cprintf (")\n");
+      indentation += indentation_amount;
+      make_command_string_internal (clauses->action);
+      indentation -= indentation_amount;
+      PRINT_DEFERRED_HEREDOCS ("");
+      if (clauses->flags & CASEPAT_FALLTHROUGH)
+       newline (";&");
+      else if (clauses->flags & CASEPAT_TESTNEXT)
+       newline (";;&");
+      else
+       newline (";;");
+      clauses = clauses->next;
+    }
+  indentation -= indentation_amount;
+}
+
+static void
+print_while_command (while_command)
+     WHILE_COM *while_command;
+{
+  print_until_or_while (while_command, "while");
+}
+
+static void
+print_until_command (while_command)
+     WHILE_COM *while_command;
+{
+  print_until_or_while (while_command, "until");
+}
+
+static void
+print_until_or_while (while_command, which)
+     WHILE_COM *while_command;
+     char *which;
+{
+  cprintf ("%s ", which);
+  skip_this_indent++;
+  make_command_string_internal (while_command->test);
+  PRINT_DEFERRED_HEREDOCS ("");
+  semicolon ();
+  cprintf (" do\n");   /* was newline ("do\n"); */
+  indentation += indentation_amount;
+  make_command_string_internal (while_command->action);
+  PRINT_DEFERRED_HEREDOCS ("");
+  indentation -= indentation_amount;
+  semicolon ();
+  newline ("done");
+}
+
+static void
+print_if_command (if_command)
+     IF_COM *if_command;
+{
+  cprintf ("if ");
+  skip_this_indent++;
+  make_command_string_internal (if_command->test);
+  semicolon ();
+  cprintf (" then\n");
+  indentation += indentation_amount;
+  make_command_string_internal (if_command->true_case);
+  PRINT_DEFERRED_HEREDOCS ("");
+  indentation -= indentation_amount;
+
+  if (if_command->false_case)
+    {
+      semicolon ();
+      newline ("else\n");
+      indentation += indentation_amount;
+      make_command_string_internal (if_command->false_case);
+      PRINT_DEFERRED_HEREDOCS ("");
+      indentation -= indentation_amount;
+    }
+  semicolon ();
+  newline ("fi");
+}
+
+#if defined (DPAREN_ARITHMETIC)
+void
+print_arith_command (arith_cmd_list)
+     WORD_LIST *arith_cmd_list;
+{
+  cprintf ("((");
+  command_print_word_list (arith_cmd_list, " ");
+  cprintf ("))");
+}
+#endif
+
+#if defined (COND_COMMAND)
+static void
+print_cond_node (cond)
+     COND_COM *cond;
+{
+  if (cond->flags & CMD_INVERT_RETURN)
+    cprintf ("! ");
+
+  if (cond->type == COND_EXPR)
+    {
+      cprintf ("( ");
+      print_cond_node (cond->left);
+      cprintf (" )");
+    }
+  else if (cond->type == COND_AND)
+    {
+      print_cond_node (cond->left);
+      cprintf (" && ");
+      print_cond_node (cond->right);
+    }
+  else if (cond->type == COND_OR)
+    {
+      print_cond_node (cond->left);
+      cprintf (" || ");
+      print_cond_node (cond->right);
+    }
+  else if (cond->type == COND_UNARY)
+    {
+      cprintf ("%s", cond->op->word);
+      cprintf (" ");
+      print_cond_node (cond->left);
+    }
+  else if (cond->type == COND_BINARY)
+    {
+      print_cond_node (cond->left);
+      cprintf (" ");
+      cprintf ("%s", cond->op->word);
+      cprintf (" ");
+      print_cond_node (cond->right);
+    }
+  else if (cond->type == COND_TERM)
+    {
+      cprintf ("%s", cond->op->word);          /* need to add quoting here */
+    }
+}
+
+void
+print_cond_command (cond)
+     COND_COM *cond;
+{
+  cprintf ("[[ ");
+  print_cond_node (cond);
+  cprintf (" ]]");
+}
+
+#ifdef DEBUG
+void
+debug_print_word_list (s, list, sep)
+     char *s;
+     WORD_LIST *list;
+     char *sep;
+{
+  WORD_LIST *w;
+
+  if (s)
+    fprintf (stderr, "%s: ", s);
+  for (w = list; w; w = w->next)
+    fprintf (stderr, "%s%s", w->word->word, w->next ? sep : "");
+  fprintf (stderr, "\n");
+}
+
+void
+debug_print_cond_command (cond)
+     COND_COM *cond;
+{
+  fprintf (stderr, "DEBUG: ");
+  command_string_index = 0;
+  print_cond_command (cond);
+  fprintf (stderr, "%s\n", the_printed_command);
+}
+#endif
+
+void
+xtrace_print_cond_term (type, invert, op, arg1, arg2)
+     int type, invert;
+     WORD_DESC *op;
+     char *arg1, *arg2;
+{
+  CHECK_XTRACE_FP;
+  command_string_index = 0;
+  fprintf (xtrace_fp, "%s", indirection_level_string ());
+  fprintf (xtrace_fp, "[[ ");
+  if (invert)
+    fprintf (xtrace_fp, "! ");
+
+  if (type == COND_UNARY)
+    {
+      fprintf (xtrace_fp, "%s ", op->word);
+      fprintf (xtrace_fp, "%s", (arg1 && *arg1) ? arg1 : "''");
+    }
+  else if (type == COND_BINARY)
+    {
+      fprintf (xtrace_fp, "%s", (arg1 && *arg1) ? arg1 : "''");
+      fprintf (xtrace_fp, " %s ", op->word);
+      fprintf (xtrace_fp, "%s", (arg2 && *arg2) ? arg2 : "''");
+    }
+
+  fprintf (xtrace_fp, " ]]\n");
+
+  fflush (xtrace_fp);
+}        
+#endif /* COND_COMMAND */
+
+#if defined (DPAREN_ARITHMETIC) || defined (ARITH_FOR_COMMAND)
+/* A function to print the words of an arithmetic command when set -x is on. */
+void
+xtrace_print_arith_cmd (list)
+     WORD_LIST *list;
+{
+  WORD_LIST *w;
+
+  CHECK_XTRACE_FP;
+  fprintf (xtrace_fp, "%s", indirection_level_string ());
+  fprintf (xtrace_fp, "(( ");
+  for (w = list; w; w = w->next)
+    fprintf (xtrace_fp, "%s%s", w->word->word, w->next ? " " : "");
+  fprintf (xtrace_fp, " ))\n");
+
+  fflush (xtrace_fp);
+}
+#endif
+
+void
+print_simple_command (simple_command)
+     SIMPLE_COM *simple_command;
+{
+  command_print_word_list (simple_command->words, " ");
+
+  if (simple_command->redirects)
+    {
+      cprintf (" ");
+      print_redirection_list (simple_command->redirects);
+    }
+}
+
+static void
+print_heredocs (heredocs)
+     REDIRECT *heredocs;
+{
+  REDIRECT *hdtail;
+
+  cprintf (" "); 
+  for (hdtail = heredocs; hdtail; hdtail = hdtail->next)
+    {
+      print_redirection (hdtail);
+      cprintf ("\n");
+    }
+  was_heredoc = 1;
+}
+
+/* Print heredocs that are attached to the command before the connector
+   represented by CSTRING.  The parsing semantics require us to print the
+   here-doc delimiters, then the connector (CSTRING), then the here-doc
+   bodies.  We don't print the connector if it's a `;', but we use it to
+   note not to print an extra space after the last heredoc body and
+   newline. */
+static void
+print_deferred_heredocs (cstring)
+     const char *cstring;
+{
+  REDIRECT *hdtail;    
+
+  for (hdtail = deferred_heredocs; hdtail; hdtail = hdtail->next)
+    {
+      cprintf (" ");
+      print_heredoc_header (hdtail);
+    }
+  if (cstring && cstring[0] && (cstring[0] != ';' || cstring[1]))
+    cprintf ("%s", cstring); 
+  if (deferred_heredocs)
+    cprintf ("\n");
+  for (hdtail = deferred_heredocs; hdtail; hdtail = hdtail->next)
+    {
+      print_heredoc_body (hdtail);
+      cprintf ("\n");
+    }
+  if (deferred_heredocs)
+    {
+      if (cstring && cstring[0] && (cstring[0] != ';' || cstring[1]))
+       cprintf (" ");  /* make sure there's at least one space */
+      dispose_redirects (deferred_heredocs);
+      was_heredoc = 1;
+    }
+  deferred_heredocs = (REDIRECT *)NULL;
+}
+      
+static void
+print_redirection_list (redirects)
+     REDIRECT *redirects;
+{
+  REDIRECT *heredocs, *hdtail, *newredir;
+  char *rw;
+
+  heredocs = (REDIRECT *)NULL;
+  hdtail = heredocs;
+
+  was_heredoc = 0;
+  while (redirects)
+    {
+      /* Defer printing the here documents until we've printed the
+        rest of the redirections. */
+      if (redirects->instruction == r_reading_until || redirects->instruction == r_deblank_reading_until)
+       {
+         newredir = copy_redirect (redirects);
+         newredir->next = (REDIRECT *)NULL;
+         if (heredocs)
+           {
+             hdtail->next = newredir;
+             hdtail = newredir;
+           }
+         else
+           hdtail = heredocs = newredir;
+       }
+      else if (redirects->instruction == r_duplicating_output_word && (redirects->flags & REDIR_VARASSIGN) == 0 && redirects->redirector.dest == 1)
+       {
+         /* Temporarily translate it as the execution code does. */
+         rw = redirects->redirectee.filename->word;
+         if (rw && *rw != '-' && DIGIT (*rw) == 0 && EXPCHAR (*rw) == 0)
+           redirects->instruction = r_err_and_out;
+         print_redirection (redirects);
+         redirects->instruction = r_duplicating_output_word;
+       }
+      else
+       print_redirection (redirects);
+
+      redirects = redirects->next;
+      if (redirects)
+       cprintf (" ");
+    }
+
+  /* Now that we've printed all the other redirections (on one line),
+     print the here documents. */
+  if (heredocs && printing_connection)
+    deferred_heredocs = heredocs;
+  else if (heredocs)
+    {
+      print_heredocs (heredocs);
+      dispose_redirects (heredocs);
+    }
+}
+
+static void
+print_heredoc_header (redirect)
+     REDIRECT *redirect;
+{
+  int kill_leading;
+  char *x;
+
+  kill_leading = redirect->instruction == r_deblank_reading_until;
+
+  /* Here doc header */
+  if (redirect->rflags & REDIR_VARASSIGN)
+    cprintf ("{%s}", redirect->redirector.filename->word);
+  else if (redirect->redirector.dest != 0)
+    cprintf ("%d", redirect->redirector.dest);
+
+  /* If the here document delimiter is quoted, single-quote it. */
+  if (redirect->redirectee.filename->flags & W_QUOTED)
+    {
+      x = sh_single_quote (redirect->here_doc_eof);
+      cprintf ("<<%s%s", kill_leading ? "-" : "", x);
+      free (x);
+    }
+  else
+    cprintf ("<<%s%s", kill_leading ? "-" : "", redirect->here_doc_eof);
+}
+
+static void
+print_heredoc_body (redirect)
+     REDIRECT *redirect;
+{
+  /* Here doc body */
+  cprintf ("%s%s", redirect->redirectee.filename->word, redirect->here_doc_eof);
+}
+
+static void
+print_redirection (redirect)
+     REDIRECT *redirect;
+{
+  int redirector, redir_fd;
+  WORD_DESC *redirectee, *redir_word;
+
+  redirectee = redirect->redirectee.filename;
+  redir_fd = redirect->redirectee.dest;
+
+  redir_word = redirect->redirector.filename;
+  redirector = redirect->redirector.dest;
+
+  switch (redirect->instruction)
+    {
+    case r_input_direction:
+      if (redirect->rflags & REDIR_VARASSIGN)
+       cprintf ("{%s}", redir_word->word);
+      else if (redirector != 0)
+       cprintf ("%d", redirector);
+      cprintf ("< %s", redirectee->word);
+      break;
+
+    case r_output_direction:
+      if (redirect->rflags & REDIR_VARASSIGN)
+       cprintf ("{%s}", redir_word->word);
+      else if (redirector != 1)
+       cprintf ("%d", redirector);
+      cprintf ("> %s", redirectee->word);
+      break;
+
+    case r_inputa_direction:   /* Redirection created by the shell. */
+      cprintf ("&");
+      break;
+
+    case r_output_force:
+      if (redirect->rflags & REDIR_VARASSIGN)
+       cprintf ("{%s}", redir_word->word);
+      else if (redirector != 1)
+       cprintf ("%d", redirector);
+      cprintf (">| %s", redirectee->word);
+      break;
+
+    case r_appending_to:
+      if (redirect->rflags & REDIR_VARASSIGN)
+       cprintf ("{%s}", redir_word->word);
+      else if (redirector != 1)
+       cprintf ("%d", redirector);
+      cprintf (">> %s", redirectee->word);
+      break;
+
+    case r_input_output:
+      if (redirect->rflags & REDIR_VARASSIGN)
+       cprintf ("{%s}", redir_word->word);
+      else if (redirector != 1)
+       cprintf ("%d", redirector);
+      cprintf ("<> %s", redirectee->word);
+      break;
+
+    case r_deblank_reading_until:
+    case r_reading_until:
+      print_heredoc_header (redirect);
+      cprintf ("\n");
+      print_heredoc_body (redirect);
+      break;
+
+    case r_reading_string:
+      if (redirect->rflags & REDIR_VARASSIGN)
+       cprintf ("{%s}", redir_word->word);
+      else if (redirector != 0)
+       cprintf ("%d", redirector);
+#if 0
+      /* Don't need to check whether or not to requote, since original quotes
+         are still intact.  The only thing that has happened is that $'...'
+         has been replaced with 'expanded ...'. */
+      if (ansic_shouldquote (redirect->redirectee.filename->word))
+       {
+         char *x;
+         x = ansic_quote (redirect->redirectee.filename->word, 0, (int *)0);
+         cprintf ("<<< %s", x);
+         free (x);
+       }
+      else
+#endif
+       cprintf ("<<< %s", redirect->redirectee.filename->word);
+      break;
+
+    case r_duplicating_input:
+      if (redirect->rflags & REDIR_VARASSIGN)
+       cprintf ("{%s}<&%d", redir_word->word, redir_fd);
+      else
+       cprintf ("%d<&%d", redirector, redir_fd);
+      break;
+
+    case r_duplicating_output:
+      if (redirect->rflags & REDIR_VARASSIGN)
+       cprintf ("{%s}>&%d", redir_word->word, redir_fd);
+      else
+       cprintf ("%d>&%d", redirector, redir_fd);
+      break;
+
+    case r_duplicating_input_word:
+      if (redirect->rflags & REDIR_VARASSIGN)
+       cprintf ("{%s}<&%s", redir_word->word, redirectee->word);
+      else
+       cprintf ("%d<&%s", redirector, redirectee->word);
+      break;
+
+    case r_duplicating_output_word:
+      if (redirect->rflags & REDIR_VARASSIGN)
+       cprintf ("{%s}>&%s", redir_word->word, redirectee->word);
+      else
+       cprintf ("%d>&%s", redirector, redirectee->word);
+      break;
+
+    case r_move_input:
+      if (redirect->rflags & REDIR_VARASSIGN)
+       cprintf ("{%s}<&%d-", redir_word->word, redir_fd);
+      else
+       cprintf ("%d<&%d-", redirector, redir_fd);
+      break;
+
+    case r_move_output:
+      if (redirect->rflags & REDIR_VARASSIGN)
+       cprintf ("{%s}>&%d-", redir_word->word, redir_fd);
+      else
+       cprintf ("%d>&%d-", redirector, redir_fd);
+      break;
+
+    case r_move_input_word:
+      if (redirect->rflags & REDIR_VARASSIGN)
+       cprintf ("{%s}<&%s-", redir_word->word, redirectee->word);
+      else
+       cprintf ("%d<&%s-", redirector, redirectee->word);
+      break;
+
+    case r_move_output_word:
+      if (redirect->rflags & REDIR_VARASSIGN)
+       cprintf ("{%s}>&%s-", redir_word->word, redirectee->word);
+      else
+       cprintf ("%d>&%s-", redirector, redirectee->word);
+      break;
+
+    case r_close_this:
+      if (redirect->rflags & REDIR_VARASSIGN)
+       cprintf ("{%s}>&-", redir_word->word);
+      else
+       cprintf ("%d>&-", redirector);
+      break;
+
+    case r_err_and_out:
+      cprintf ("&> %s", redirectee->word);
+      break;
+
+    case r_append_err_and_out:
+      cprintf ("&>> %s", redirectee->word);
+      break;
+    }
+}
+
+static void
+reset_locals ()
+{
+  inside_function_def = 0;
+  indentation = 0;
+  printing_connection = 0;
+  deferred_heredocs = 0;
+}
+
+static void
+print_function_def (func)
+     FUNCTION_DEF *func;
+{
+  COMMAND *cmdcopy;
+  REDIRECT *func_redirects;
+
+  func_redirects = NULL;
+  /* When in posix mode, print functions as posix specifies them. */
+  if (posixly_correct == 0)
+    cprintf ("function %s () \n", func->name->word);
+  else
+    cprintf ("%s () \n", func->name->word);
+  add_unwind_protect (reset_locals, 0);
+
+  indent (indentation);
+  cprintf ("{ \n");
+
+  inside_function_def++;
+  indentation += indentation_amount;
+
+  cmdcopy = copy_command (func->command);
+  if (cmdcopy->type == cm_group)
+    {
+      func_redirects = cmdcopy->redirects;
+      cmdcopy->redirects = (REDIRECT *)NULL;
+    }
+  make_command_string_internal (cmdcopy->type == cm_group
+                                       ? cmdcopy->value.Group->command
+                                       : cmdcopy);
+  /* XXX - PRINT_DEFERRED_HEREDOCS (""); ? */
+
+  remove_unwind_protect ();
+  indentation -= indentation_amount;
+  inside_function_def--;
+
+  if (func_redirects)
+    { /* { */
+      newline ("} ");
+      print_redirection_list (func_redirects);
+      cmdcopy->redirects = func_redirects;
+    }
+  else
+    newline ("}");
+
+  dispose_command (cmdcopy);
+}
+
+/* Return the string representation of the named function.
+   NAME is the name of the function.
+   COMMAND is the function body.  It should be a GROUP_COM.
+   flags&FUNC_MULTILINE is non-zero to pretty-print, or zero for all on one line.
+   flags&FUNC_EXTERNAL means convert from internal to external form
+  */
+char *
+named_function_string (name, command, flags)
+     char *name;
+     COMMAND *command;
+     int flags;
+{
+  char *result;
+  int old_indent, old_amount;
+  COMMAND *cmdcopy;
+  REDIRECT *func_redirects;
+
+  old_indent = indentation;
+  old_amount = indentation_amount;
+  command_string_index = was_heredoc = 0;
+  deferred_heredocs = 0;
+
+  if (name && *name)
+    cprintf ("%s ", name);
+
+  cprintf ("() ");
+
+  if ((flags & FUNC_MULTILINE) == 0)
+    {
+      indentation = 1;
+      indentation_amount = 0;
+    }
+  else
+    {
+      cprintf ("\n");
+      indentation += indentation_amount;
+    }
+
+  inside_function_def++;
+
+  cprintf ((flags & FUNC_MULTILINE) ? "{ \n" : "{ ");
+
+  cmdcopy = copy_command (command);
+  /* Take any redirections specified in the function definition (which should
+     apply to the function as a whole) and save them for printing later. */
+  func_redirects = (REDIRECT *)NULL;
+  if (cmdcopy->type == cm_group)
+    {
+      func_redirects = cmdcopy->redirects;
+      cmdcopy->redirects = (REDIRECT *)NULL;
+    }
+  make_command_string_internal (cmdcopy->type == cm_group
+                                       ? cmdcopy->value.Group->command
+                                       : cmdcopy);
+  /* XXX - PRINT_DEFERRED_HEREDOCS (""); ? */
+
+  indentation = old_indent;
+  indentation_amount = old_amount;
+  inside_function_def--;
+
+  if (func_redirects)
+    { /* { */
+      newline ("} ");
+      print_redirection_list (func_redirects);
+      cmdcopy->redirects = func_redirects;
+    }
+  else
+    newline ("}");
+
+  result = the_printed_command;
+
+  if ((flags & FUNC_MULTILINE) == 0)
+    {
+#if 0
+      register int i;
+      for (i = 0; result[i]; i++)
+       if (result[i] == '\n')
+         {
+           strcpy (result + i, result + i + 1);
+           --i;
+         }
+#else
+      if (result[2] == '\n')   /* XXX -- experimental */
+       memmove (result + 2, result + 3, strlen (result) - 2);
+       
+#endif
+    }
+
+  dispose_command (cmdcopy);
+
+  if (flags & FUNC_EXTERNAL)
+    result = remove_quoted_escapes (result);
+
+  return (result);
+}
+
+static void
+newline (string)
+     char *string;
+{
+  cprintf ("\n");
+  indent (indentation);
+  if (string && *string)
+    cprintf ("%s", string);
+}
+
+static char *indentation_string;
+static int indentation_size;
+
+static void
+indent (amount)
+     int amount;
+{
+  register int i;
+
+  RESIZE_MALLOCED_BUFFER (indentation_string, 0, amount, indentation_size, 16);
+
+  for (i = 0; amount > 0; amount--)
+    indentation_string[i++] = ' ';
+  indentation_string[i] = '\0';
+  cprintf ("%s", indentation_string);
+}
+
+static void
+semicolon ()
+{
+  if (command_string_index > 0 &&
+       (the_printed_command[command_string_index - 1] == '&' ||
+       the_printed_command[command_string_index - 1] == '\n'))
+    return;
+  cprintf (";");
+}
+
+/* How to make the string. */
+static void
+#if defined (PREFER_STDARG)
+cprintf (const char *control, ...)
+#else
+cprintf (control, va_alist)
+     const char *control;
+     va_dcl
+#endif
+{
+  register const char *s;
+  char char_arg[2], *argp, intbuf[INT_STRLEN_BOUND (int) + 1];
+  int digit_arg, arg_len, c;
+  va_list args;
+
+  SH_VA_START (args, control);
+
+  arg_len = strlen (control);
+  the_printed_command_resize (arg_len + 1);
+
+  char_arg[1] = '\0';
+  s = control;
+  while (s && *s)
+    {
+      c = *s++;
+      argp = (char *)NULL;
+      if (c != '%' || !*s)
+       {
+         char_arg[0] = c;
+         argp = char_arg;
+         arg_len = 1;
+       }
+      else
+       {
+         c = *s++;
+         switch (c)
+           {
+           case '%':
+             char_arg[0] = c;
+             argp = char_arg;
+             arg_len = 1;
+             break;
+
+           case 's':
+             argp = va_arg (args, char *);
+             arg_len = strlen (argp);
+             break;
+
+           case 'd':
+             /* Represent an out-of-range file descriptor with an out-of-range
+                integer value.  We can do this because the only use of `%d' in
+                the calls to cprintf is to output a file descriptor number for
+                a redirection. */
+             digit_arg = va_arg (args, int);
+             if (digit_arg < 0)
+               {
+                 sprintf (intbuf, "%u", (unsigned)-1);
+                 argp = intbuf;
+               }
+             else
+               argp = inttostr (digit_arg, intbuf, sizeof (intbuf));
+             arg_len = strlen (argp);
+             break;
+
+           case 'c':
+             char_arg[0] = va_arg (args, int);
+             argp = char_arg;
+             arg_len = 1;
+             break;
+
+           default:
+             programming_error (_("cprintf: `%c': invalid format character"), c);
+             /*NOTREACHED*/
+           }
+       }
+
+      if (argp && arg_len)
+       {
+         the_printed_command_resize (arg_len + 1);
+         FASTCOPY (argp, the_printed_command + command_string_index, arg_len);
+         command_string_index += arg_len;
+       }
+    }
+
+  va_end (args);
+
+  the_printed_command[command_string_index] = '\0';
+}
+
+/* Ensure that there is enough space to stuff LENGTH characters into
+   THE_PRINTED_COMMAND. */
+static void
+the_printed_command_resize (length)
+     int length;
+{
+  if (the_printed_command == 0)
+    {
+      the_printed_command_size = (length + PRINTED_COMMAND_INITIAL_SIZE - 1) & ~(PRINTED_COMMAND_INITIAL_SIZE - 1);
+      the_printed_command = (char *)xmalloc (the_printed_command_size);
+      command_string_index = 0;
+    }
+  else if ((command_string_index + length) >= the_printed_command_size)
+    {
+      int new;
+      new = command_string_index + length + 1;
+
+      /* Round up to the next multiple of PRINTED_COMMAND_GROW_SIZE. */
+      new = (new + PRINTED_COMMAND_GROW_SIZE - 1) & ~(PRINTED_COMMAND_GROW_SIZE - 1);
+      the_printed_command_size = new;
+
+      the_printed_command = (char *)xrealloc (the_printed_command, the_printed_command_size);
+    }
+}
+
+#if defined (HAVE_VPRINTF)
+/* ``If vprintf is available, you may assume that vfprintf and vsprintf are
+     also available.'' */
+
+static void
+#if defined (PREFER_STDARG)
+xprintf (const char *format, ...)
+#else
+xprintf (format, va_alist)
+     const char *format;
+     va_dcl
+#endif
+{
+  va_list args;
+
+  SH_VA_START (args, format);
+
+  vfprintf (stdout, format, args);
+  va_end (args);
+}
+
+#else
+
+static void
+xprintf (format, arg1, arg2, arg3, arg4, arg5)
+     const char *format;
+{
+  printf (format, arg1, arg2, arg3, arg4, arg5);
+}
+
+#endif /* !HAVE_VPRINTF */
diff --git a/shell.c~ b/shell.c~
new file mode 100644 (file)
index 0000000..b8d9b53
--- /dev/null
+++ b/shell.c~
@@ -0,0 +1,1911 @@
+/* shell.c -- GNU's idea of the POSIX shell specification. */
+
+/* Copyright (C) 1987-2012 Free Software Foundation, Inc.
+
+   This file is part of GNU Bash, the Bourne Again SHell.
+
+   Bash is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
+
+   Bash is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with Bash.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+/*
+  Birthdate:
+  Sunday, January 10th, 1988.
+  Initial author: Brian Fox
+*/
+#define INSTALL_DEBUG_MODE
+
+#include "config.h"
+
+#include "bashtypes.h"
+#if !defined (_MINIX) && defined (HAVE_SYS_FILE_H)
+#  include <sys/file.h>
+#endif
+#include "posixstat.h"
+#include "posixtime.h"
+#include "bashansi.h"
+#include <stdio.h>
+#include <signal.h>
+#include <errno.h>
+#include "filecntl.h"
+#include <pwd.h>
+
+#if defined (HAVE_UNISTD_H)
+#  include <unistd.h>
+#endif
+
+#include "bashintl.h"
+
+#define NEED_SH_SETLINEBUF_DECL                /* used in externs.h */
+
+#include "shell.h"
+#include "flags.h"
+#include "trap.h"
+#include "mailcheck.h"
+#include "builtins.h"
+#include "builtins/common.h"
+
+#if defined (JOB_CONTROL)
+#include "jobs.h"
+#endif /* JOB_CONTROL */
+
+#include "input.h"
+#include "execute_cmd.h"
+#include "findcmd.h"
+
+#if defined (USING_BASH_MALLOC) && defined (DEBUG) && !defined (DISABLE_MALLOC_WRAPPERS)
+#  include <malloc/shmalloc.h>
+#endif
+
+#if defined (HISTORY)
+#  include "bashhist.h"
+#  include <readline/history.h>
+#endif
+
+#if defined (READLINE)
+#  include <readline/readline.h>
+#  include "bashline.h"
+#endif
+
+#include <tilde/tilde.h>
+#include <glob/strmatch.h>
+
+#if defined (__OPENNT)
+#  include <opennt/opennt.h>
+#endif
+
+#if !defined (HAVE_GETPW_DECLS)
+extern struct passwd *getpwuid ();
+#endif /* !HAVE_GETPW_DECLS */
+
+#if !defined (errno)
+extern int errno;
+#endif
+
+#if defined (NO_MAIN_ENV_ARG)
+extern char **environ; /* used if no third argument to main() */
+#endif
+
+extern char *dist_version, *release_status;
+extern int patch_level, build_version;
+extern int shell_level;
+extern int subshell_environment;
+extern int running_in_background;
+extern int last_command_exit_value;
+extern int line_number;
+extern int expand_aliases;
+extern int array_needs_making;
+extern int gnu_error_format;
+extern char *primary_prompt, *secondary_prompt;
+extern char *this_command_name;
+
+/* Non-zero means that this shell has already been run; i.e. you should
+   call shell_reinitialize () if you need to start afresh. */
+int shell_initialized = 0;
+
+COMMAND *global_command = (COMMAND *)NULL;
+
+/* Information about the current user. */
+struct user_info current_user =
+{
+  (uid_t)-1, (uid_t)-1, (gid_t)-1, (gid_t)-1,
+  (char *)NULL, (char *)NULL, (char *)NULL
+};
+
+/* The current host's name. */
+char *current_host_name = (char *)NULL;
+
+/* Non-zero means that this shell is a login shell.
+   Specifically:
+   0 = not login shell.
+   1 = login shell from getty (or equivalent fake out)
+  -1 = login shell from "--login" (or -l) flag.
+  -2 = both from getty, and from flag.
+ */
+int login_shell = 0;
+
+/* Non-zero means that at this moment, the shell is interactive.  In
+   general, this means that the shell is at this moment reading input
+   from the keyboard. */
+int interactive = 0;
+
+/* Non-zero means that the shell was started as an interactive shell. */
+int interactive_shell = 0;
+
+/* Non-zero means to send a SIGHUP to all jobs when an interactive login
+   shell exits. */
+int hup_on_exit = 0;
+
+/* Non-zero means to list status of running and stopped jobs at shell exit */
+int check_jobs_at_exit = 0;
+
+/* Non-zero means to change to a directory name supplied as a command name */
+int autocd = 0;
+
+/* Tells what state the shell was in when it started:
+       0 = non-interactive shell script
+       1 = interactive
+       2 = -c command
+       3 = wordexp evaluation
+   This is a superset of the information provided by interactive_shell.
+*/
+int startup_state = 0;
+
+/* Special debugging helper. */
+int debugging_login_shell = 0;
+
+/* The environment that the shell passes to other commands. */
+char **shell_environment;
+
+/* Non-zero when we are executing a top-level command. */
+int executing = 0;
+
+/* The number of commands executed so far. */
+int current_command_number = 1;
+
+/* Non-zero is the recursion depth for commands. */
+int indirection_level = 0;
+
+/* The name of this shell, as taken from argv[0]. */
+char *shell_name = (char *)NULL;
+
+/* time in seconds when the shell was started */
+time_t shell_start_time;
+
+/* Are we running in an emacs shell window? */
+int running_under_emacs;
+
+/* Do we have /dev/fd? */
+#ifdef HAVE_DEV_FD
+int have_devfd = HAVE_DEV_FD;
+#else
+int have_devfd = 0;
+#endif
+
+/* The name of the .(shell)rc file. */
+static char *bashrc_file = DEFAULT_BASHRC;
+
+/* Non-zero means to act more like the Bourne shell on startup. */
+static int act_like_sh;
+
+/* Non-zero if this shell is being run by `su'. */
+static int su_shell;
+
+/* Non-zero if we have already expanded and sourced $ENV. */
+static int sourced_env;
+
+/* Is this shell running setuid? */
+static int running_setuid;
+
+/* Values for the long-winded argument names. */
+static int debugging;                  /* Do debugging things. */
+static int no_rc;                      /* Don't execute ~/.bashrc */
+static int no_profile;                 /* Don't execute .profile */
+static int do_version;                 /* Display interesting version info. */
+static int make_login_shell;           /* Make this shell be a `-bash' shell. */
+static int want_initial_help;          /* --help option */
+
+int debugging_mode = 0;                /* In debugging mode with --debugger */
+#if defined (READLINE)
+int no_line_editing = 0;       /* non-zero -> don't do fancy line editing. */
+#else
+int no_line_editing = 1;       /* can't have line editing without readline */
+#endif
+int dump_translatable_strings; /* Dump strings in $"...", don't execute. */
+int dump_po_strings;           /* Dump strings in $"..." in po format */
+int wordexp_only = 0;          /* Do word expansion only */
+int protected_mode = 0;                /* No command substitution with --wordexp */
+
+#if defined (STRICT_POSIX)
+int posixly_correct = 1;       /* Non-zero means posix.2 superset. */
+#else
+int posixly_correct = 0;       /* Non-zero means posix.2 superset. */
+#endif
+
+/* Some long-winded argument names.  These are obviously new. */
+#define Int 1
+#define Charp 2
+static const struct {
+  const char *name;
+  int type;
+  int *int_value;
+  char **char_value;
+} long_args[] = {
+  { "debug", Int, &debugging, (char **)0x0 },
+#if defined (DEBUGGER)
+  { "debugger", Int, &debugging_mode, (char **)0x0 },
+#endif
+  { "dump-po-strings", Int, &dump_po_strings, (char **)0x0 },
+  { "dump-strings", Int, &dump_translatable_strings, (char **)0x0 },
+  { "help", Int, &want_initial_help, (char **)0x0 },
+  { "init-file", Charp, (int *)0x0, &bashrc_file },
+  { "login", Int, &make_login_shell, (char **)0x0 },
+  { "noediting", Int, &no_line_editing, (char **)0x0 },
+  { "noprofile", Int, &no_profile, (char **)0x0 },
+  { "norc", Int, &no_rc, (char **)0x0 },
+  { "posix", Int, &posixly_correct, (char **)0x0 },
+#if defined (WORDEXP_OPTION)
+  { "protected", Int, &protected_mode, (char **)0x0 },
+#endif
+  { "rcfile", Charp, (int *)0x0, &bashrc_file },
+#if defined (RESTRICTED_SHELL)
+  { "restricted", Int, &restricted, (char **)0x0 },
+#endif
+  { "verbose", Int, &echo_input_at_read, (char **)0x0 },
+  { "version", Int, &do_version, (char **)0x0 },
+#if defined (WORDEXP_OPTION)
+  { "wordexp", Int, &wordexp_only, (char **)0x0 },
+#endif
+  { (char *)0x0, Int, (int *)0x0, (char **)0x0 }
+};
+
+/* These are extern so execute_simple_command can set them, and then
+   longjmp back to main to execute a shell script, instead of calling
+   main () again and resulting in indefinite, possibly fatal, stack
+   growth. */
+procenv_t subshell_top_level;
+int subshell_argc;
+char **subshell_argv;
+char **subshell_envp;
+
+char *exec_argv0;
+
+#if defined (BUFFERED_INPUT)
+/* The file descriptor from which the shell is reading input. */
+int default_buffered_input = -1;
+#endif
+
+/* The following two variables are not static so they can show up in $-. */
+int read_from_stdin;           /* -s flag supplied */
+int want_pending_command;      /* -c flag supplied */
+
+/* This variable is not static so it can be bound to $BASH_EXECUTION_STRING */
+char *command_execution_string;        /* argument to -c option */
+
+int malloc_trace_at_exit = 0;
+
+static int shell_reinitialized = 0;
+
+static FILE *default_input;
+
+static STRING_INT_ALIST *shopt_alist;
+static int shopt_ind = 0, shopt_len = 0;
+
+static int parse_long_options __P((char **, int, int));
+static int parse_shell_options __P((char **, int, int));
+static int bind_args __P((char **, int, int, int));
+
+static void start_debugger __P((void));
+
+static void add_shopt_to_alist __P((char *, int));
+static void run_shopt_alist __P((void));
+
+static void execute_env_file __P((char *));
+static void run_startup_files __P((void));
+static int open_shell_script __P((char *));
+static void set_bash_input __P((void));
+static int run_one_command __P((char *));
+#if defined (WORDEXP_OPTION)
+static int run_wordexp __P((char *));
+#endif
+
+static int uidget __P((void));
+
+static void init_interactive __P((void));
+static void init_noninteractive __P((void));
+static void init_interactive_script __P((void));
+
+static void set_shell_name __P((char *));
+static void shell_initialize __P((void));
+static void shell_reinitialize __P((void));
+
+static void show_shell_usage __P((FILE *, int));
+
+#ifdef __CYGWIN__
+static void
+_cygwin32_check_tmp ()
+{
+  struct stat sb;
+
+  if (stat ("/tmp", &sb) < 0)
+    internal_warning (_("could not find /tmp, please create!"));
+  else
+    {
+      if (S_ISDIR (sb.st_mode) == 0)
+       internal_warning (_("/tmp must be a valid directory name"));
+    }
+}
+#endif /* __CYGWIN__ */
+
+#if defined (NO_MAIN_ENV_ARG)
+/* systems without third argument to main() */
+int
+main (argc, argv)
+     int argc;
+     char **argv;
+#else /* !NO_MAIN_ENV_ARG */
+int
+main (argc, argv, env)
+     int argc;
+     char **argv, **env;
+#endif /* !NO_MAIN_ENV_ARG */
+{
+  register int i;
+  int code, old_errexit_flag;
+#if defined (RESTRICTED_SHELL)
+  int saverst;
+#endif
+  volatile int locally_skip_execution;
+  volatile int arg_index, top_level_arg_index;
+#ifdef __OPENNT
+  char **env;
+
+  env = environ;
+#endif /* __OPENNT */
+
+  USE_VAR(argc);
+  USE_VAR(argv);
+  USE_VAR(env);
+  USE_VAR(code);
+  USE_VAR(old_errexit_flag);
+#if defined (RESTRICTED_SHELL)
+  USE_VAR(saverst);
+#endif
+
+  /* Catch early SIGINTs. */
+  code = setjmp_nosigs (top_level);
+  if (code)
+    exit (2);
+
+  xtrace_init ();
+
+#if defined (USING_BASH_MALLOC) && defined (DEBUG) && !defined (DISABLE_MALLOC_WRAPPERS)
+#  if 1
+  malloc_set_register (1);
+#  endif
+#endif
+
+  check_dev_tty ();
+
+#ifdef __CYGWIN__
+  _cygwin32_check_tmp ();
+#endif /* __CYGWIN__ */
+
+  /* Wait forever if we are debugging a login shell. */
+  while (debugging_login_shell) sleep (3);
+
+  set_default_locale ();
+
+  running_setuid = uidget ();
+
+  if (getenv ("POSIXLY_CORRECT") || getenv ("POSIX_PEDANTIC"))
+    posixly_correct = 1;
+
+#if defined (USE_GNU_MALLOC_LIBRARY)
+  mcheck (programming_error, (void (*) ())0);
+#endif /* USE_GNU_MALLOC_LIBRARY */
+
+  if (setjmp (subshell_top_level))
+    {
+      argc = subshell_argc;
+      argv = subshell_argv;
+      env = subshell_envp;
+      sourced_env = 0;
+    }
+
+  shell_reinitialized = 0;
+
+  /* Initialize `local' variables for all `invocations' of main (). */
+  arg_index = 1;
+  if (arg_index > argc)
+    arg_index = argc;
+  command_execution_string = (char *)NULL;
+  want_pending_command = locally_skip_execution = read_from_stdin = 0;
+  default_input = stdin;
+#if defined (BUFFERED_INPUT)
+  default_buffered_input = -1;
+#endif
+
+  /* Fix for the `infinite process creation' bug when running shell scripts
+     from startup files on System V. */
+  login_shell = make_login_shell = 0;
+
+  /* If this shell has already been run, then reinitialize it to a
+     vanilla state. */
+  if (shell_initialized || shell_name)
+    {
+      /* Make sure that we do not infinitely recurse as a login shell. */
+      if (*shell_name == '-')
+       shell_name++;
+
+      shell_reinitialize ();
+      if (setjmp_nosigs (top_level))
+       exit (2);
+    }
+
+  shell_environment = env;
+  set_shell_name (argv[0]);
+  shell_start_time = NOW;      /* NOW now defined in general.h */
+
+  /* Parse argument flags from the input line. */
+
+  /* Find full word arguments first. */
+  arg_index = parse_long_options (argv, arg_index, argc);
+
+  if (want_initial_help)
+    {
+      show_shell_usage (stdout, 1);
+      exit (EXECUTION_SUCCESS);
+    }
+
+  if (do_version)
+    {
+      show_shell_version (1);
+      exit (EXECUTION_SUCCESS);
+    }
+
+  /* All done with full word options; do standard shell option parsing.*/
+  this_command_name = shell_name;      /* for error reporting */
+  arg_index = parse_shell_options (argv, arg_index, argc);
+
+  /* If user supplied the "--login" (or -l) flag, then set and invert
+     LOGIN_SHELL. */
+  if (make_login_shell)
+    {
+      login_shell++;
+      login_shell = -login_shell;
+    }
+
+  set_login_shell ("login_shell", login_shell != 0);
+
+  if (dump_po_strings)
+    dump_translatable_strings = 1;
+
+  if (dump_translatable_strings)
+    read_but_dont_execute = 1;
+
+  if (running_setuid && privileged_mode == 0)
+    disable_priv_mode ();
+
+  /* Need to get the argument to a -c option processed in the
+     above loop.  The next arg is a command to execute, and the
+     following args are $0...$n respectively. */
+  if (want_pending_command)
+    {
+      command_execution_string = argv[arg_index];
+      if (command_execution_string == 0)
+       {
+         report_error (_("%s: option requires an argument"), "-c");
+         exit (EX_BADUSAGE);
+       }
+      arg_index++;
+    }
+  this_command_name = (char *)NULL;
+
+  cmd_init();          /* initialize the command object caches */
+
+  /* First, let the outside world know about our interactive status.
+     A shell is interactive if the `-i' flag was given, or if all of
+     the following conditions are met:
+       no -c command
+       no arguments remaining or the -s flag given
+       standard input is a terminal
+       standard error is a terminal
+     Refer to Posix.2, the description of the `sh' utility. */
+
+  if (forced_interactive ||            /* -i flag */
+      (!command_execution_string &&    /* No -c command and ... */
+       wordexp_only == 0 &&            /* No --wordexp and ... */
+       ((arg_index == argc) ||         /*   no remaining args or... */
+       read_from_stdin) &&             /*   -s flag with args, and */
+       isatty (fileno (stdin)) &&      /* Input is a terminal and */
+       isatty (fileno (stderr))))      /* error output is a terminal. */
+    init_interactive ();
+  else
+    init_noninteractive ();
+
+  /*
+   * Some systems have the bad habit of starting login shells with lots of open
+   * file descriptors.  For instance, most systems that have picked up the
+   * pre-4.0 Sun YP code leave a file descriptor open each time you call one
+   * of the getpw* functions, and it's set to be open across execs.  That
+   * means one for login, one for xterm, one for shelltool, etc.  There are
+   * also systems that open persistent FDs to other agents or files as part
+   * of process startup; these need to be set to be close-on-exec.
+   */
+  if (login_shell && interactive_shell)
+    {
+      for (i = 3; i < 20; i++)
+       SET_CLOSE_ON_EXEC (i);
+    }
+
+  /* If we're in a strict Posix.2 mode, turn on interactive comments,
+     alias expansion in non-interactive shells, and other Posix.2 things. */
+  if (posixly_correct)
+    {
+      bind_variable ("POSIXLY_CORRECT", "y", 0);
+      sv_strict_posix ("POSIXLY_CORRECT");
+    }
+
+  /* Now we run the shopt_alist and process the options. */
+  if (shopt_alist)
+    run_shopt_alist ();
+
+  /* From here on in, the shell must be a normal functioning shell.
+     Variables from the environment are expected to be set, etc. */
+  shell_initialize ();
+
+  set_default_lang ();
+  set_default_locale_vars ();
+
+  /*
+   * M-x term -> TERM=eterm EMACS=22.1 (term:0.96)     (eterm)
+   * M-x shell -> TERM=dumb EMACS=t                    (no line editing)
+   * M-x terminal -> TERM=emacs-em7955 EMACS=          (line editing)
+   */
+  if (interactive_shell)
+    {
+      char *term, *emacs;
+
+      term = get_string_value ("TERM");
+      emacs = get_string_value ("EMACS");
+
+      /* Not sure any emacs terminal emulator sets TERM=emacs any more */
+      no_line_editing |= term && (STREQ (term, "emacs"));
+      no_line_editing |= emacs && emacs[0] == 't' && emacs[1] == '\0' && STREQ (term, "dumb");
+
+      /* running_under_emacs == 2 for `eterm' */
+      running_under_emacs = (emacs != 0) || (term && STREQN (term, "emacs", 5));
+      running_under_emacs += term && STREQN (term, "eterm", 5) && emacs && strstr (emacs, "term");
+
+      if (running_under_emacs)
+       gnu_error_format = 1;
+    }
+
+  top_level_arg_index = arg_index;
+  old_errexit_flag = exit_immediately_on_error;
+
+  /* Give this shell a place to longjmp to before executing the
+     startup files.  This allows users to press C-c to abort the
+     lengthy startup. */
+  code = setjmp (top_level);
+  if (code)
+    {
+      if (code == EXITPROG || code == ERREXIT)
+       exit_shell (last_command_exit_value);
+      else
+       {
+#if defined (JOB_CONTROL)
+         /* Reset job control, since run_startup_files turned it off. */
+         set_job_control (interactive_shell);
+#endif
+         /* Reset value of `set -e', since it's turned off before running
+            the startup files. */
+         exit_immediately_on_error += old_errexit_flag;
+         locally_skip_execution++;
+       }
+    }
+
+  arg_index = top_level_arg_index;
+
+  /* Execute the start-up scripts. */
+
+  if (interactive_shell == 0)
+    {
+      unbind_variable ("PS1");
+      unbind_variable ("PS2");
+      interactive = 0;
+#if 0
+      /* This has already been done by init_noninteractive */
+      expand_aliases = posixly_correct;
+#endif
+    }
+  else
+    {
+      change_flag ('i', FLAG_ON);
+      interactive = 1;
+    }
+
+#if defined (RESTRICTED_SHELL)
+  /* Set restricted_shell based on whether the basename of $0 indicates that
+     the shell should be restricted or if the `-r' option was supplied at
+     startup. */
+  restricted_shell = shell_is_restricted (shell_name);
+
+  /* If the `-r' option is supplied at invocation, make sure that the shell
+     is not in restricted mode when running the startup files. */
+  saverst = restricted;
+itrace("main: set saverst = %d", saverst);
+  restricted = 0;
+#endif
+
+  /* The startup files are run with `set -e' temporarily disabled. */
+  if (locally_skip_execution == 0 && running_setuid == 0)
+    {
+      old_errexit_flag = exit_immediately_on_error;
+      exit_immediately_on_error = 0;
+
+      run_startup_files ();
+      exit_immediately_on_error += old_errexit_flag;
+    }
+
+  /* If we are invoked as `sh', turn on Posix mode. */
+  if (act_like_sh)
+    {
+      bind_variable ("POSIXLY_CORRECT", "y", 0);
+      sv_strict_posix ("POSIXLY_CORRECT");
+    }
+
+#if defined (RESTRICTED_SHELL)
+  /* Turn on the restrictions after executing the startup files.  This
+     means that `bash -r' or `set -r' invoked from a startup file will
+     turn on the restrictions after the startup files are executed. */
+  restricted = saverst || restricted;
+  if (shell_reinitialized == 0)
+    maybe_make_restricted (shell_name);
+#endif /* RESTRICTED_SHELL */
+
+#if defined (WORDEXP_OPTION)
+  if (wordexp_only)
+    {
+      startup_state = 3;
+      last_command_exit_value = run_wordexp (argv[arg_index]);
+      exit_shell (last_command_exit_value);
+    }
+#endif
+
+  if (command_execution_string)
+    {
+      arg_index = bind_args (argv, arg_index, argc, 0);
+      startup_state = 2;
+
+      if (debugging_mode)
+       start_debugger ();
+
+#if defined (ONESHOT)
+      executing = 1;
+      run_one_command (command_execution_string);
+      exit_shell (last_command_exit_value);
+#else /* ONESHOT */
+      with_input_from_string (command_execution_string, "-c");
+      goto read_and_execute;
+#endif /* !ONESHOT */
+    }
+
+  /* Get possible input filename and set up default_buffered_input or
+     default_input as appropriate. */
+  if (arg_index != argc && read_from_stdin == 0)
+    {
+      open_shell_script (argv[arg_index]);
+      arg_index++;
+    }
+  else if (interactive == 0)
+    /* In this mode, bash is reading a script from stdin, which is a
+       pipe or redirected file. */
+#if defined (BUFFERED_INPUT)
+    default_buffered_input = fileno (stdin);   /* == 0 */
+#else
+    setbuf (default_input, (char *)NULL);
+#endif /* !BUFFERED_INPUT */
+
+  set_bash_input ();
+
+  /* Bind remaining args to $1 ... $n */
+  arg_index = bind_args (argv, arg_index, argc, 1);
+
+  if (debugging_mode && locally_skip_execution == 0 && running_setuid == 0 && dollar_vars[1])
+    start_debugger ();
+
+  /* Do the things that should be done only for interactive shells. */
+  if (interactive_shell)
+    {
+      /* Set up for checking for presence of mail. */
+      reset_mail_timer ();
+      init_mail_dates ();
+
+#if defined (HISTORY)
+      /* Initialize the interactive history stuff. */
+      bash_initialize_history ();
+      /* Don't load the history from the history file if we've already
+        saved some lines in this session (e.g., by putting `history -s xx'
+        into one of the startup files). */
+      if (shell_initialized == 0 && history_lines_this_session == 0)
+       load_history ();
+#endif /* HISTORY */
+
+      /* Initialize terminal state for interactive shells after the
+        .bash_profile and .bashrc are interpreted. */
+      get_tty_state ();
+    }
+
+#if !defined (ONESHOT)
+ read_and_execute:
+#endif /* !ONESHOT */
+
+  shell_initialized = 1;
+
+  /* Read commands until exit condition. */
+  reader_loop ();
+  exit_shell (last_command_exit_value);
+}
+
+static int
+parse_long_options (argv, arg_start, arg_end)
+     char **argv;
+     int arg_start, arg_end;
+{
+  int arg_index, longarg, i;
+  char *arg_string;
+
+  arg_index = arg_start;
+  while ((arg_index != arg_end) && (arg_string = argv[arg_index]) &&
+        (*arg_string == '-'))
+    {
+      longarg = 0;
+
+      /* Make --login equivalent to -login. */
+      if (arg_string[1] == '-' && arg_string[2])
+       {
+         longarg = 1;
+         arg_string++;
+       }
+
+      for (i = 0; long_args[i].name; i++)
+       {
+         if (STREQ (arg_string + 1, long_args[i].name))
+           {
+             if (long_args[i].type == Int)
+               *long_args[i].int_value = 1;
+             else if (argv[++arg_index] == 0)
+               {
+                 report_error (_("%s: option requires an argument"), long_args[i].name);
+                 exit (EX_BADUSAGE);
+               }
+             else
+               *long_args[i].char_value = argv[arg_index];
+
+             break;
+           }
+       }
+      if (long_args[i].name == 0)
+       {
+         if (longarg)
+           {
+             report_error (_("%s: invalid option"), argv[arg_index]);
+             show_shell_usage (stderr, 0);
+             exit (EX_BADUSAGE);
+           }
+         break;                /* No such argument.  Maybe flag arg. */
+       }
+
+      arg_index++;
+    }
+
+  return (arg_index);
+}
+
+static int
+parse_shell_options (argv, arg_start, arg_end)
+     char **argv;
+     int arg_start, arg_end;
+{
+  int arg_index;
+  int arg_character, on_or_off, next_arg, i;
+  char *o_option, *arg_string;
+
+  arg_index = arg_start;
+  while (arg_index != arg_end && (arg_string = argv[arg_index]) &&
+        (*arg_string == '-' || *arg_string == '+'))
+    {
+      /* There are flag arguments, so parse them. */
+      next_arg = arg_index + 1;
+
+      /* A single `-' signals the end of options.  From the 4.3 BSD sh.
+        An option `--' means the same thing; this is the standard
+        getopt(3) meaning. */
+      if (arg_string[0] == '-' &&
+          (arg_string[1] == '\0' ||
+            (arg_string[1] == '-' && arg_string[2] == '\0')))
+       return (next_arg);
+
+      i = 1;
+      on_or_off = arg_string[0];
+      while (arg_character = arg_string[i++])
+       {
+         switch (arg_character)
+           {
+           case 'c':
+             want_pending_command = 1;
+             break;
+
+           case 'l':
+             make_login_shell = 1;
+             break;
+
+           case 's':
+             read_from_stdin = 1;
+             break;
+
+           case 'o':
+             o_option = argv[next_arg];
+             if (o_option == 0)
+               {
+                 list_minus_o_opts (-1, (on_or_off == '-') ? 0 : 1);
+                 break;
+               }
+             if (set_minus_o_option (on_or_off, o_option) != EXECUTION_SUCCESS)
+               exit (EX_BADUSAGE);
+             next_arg++;
+             break;
+
+           case 'O':
+             /* Since some of these can be overridden by the normal
+                interactive/non-interactive shell initialization or
+                initializing posix mode, we save the options and process
+                them after initialization. */
+             o_option = argv[next_arg];
+             if (o_option == 0)
+               {
+                 shopt_listopt (o_option, (on_or_off == '-') ? 0 : 1);
+                 break;
+               }
+             add_shopt_to_alist (o_option, on_or_off);
+             next_arg++;
+             break;
+
+           case 'D':
+             dump_translatable_strings = 1;
+             break;
+
+           default:
+             if (change_flag (arg_character, on_or_off) == FLAG_ERROR)
+               {
+                 report_error (_("%c%c: invalid option"), on_or_off, arg_character);
+                 show_shell_usage (stderr, 0);
+                 exit (EX_BADUSAGE);
+               }
+           }
+       }
+      /* Can't do just a simple increment anymore -- what about
+        "bash -abouo emacs ignoreeof -hP"? */
+      arg_index = next_arg;
+    }
+
+  return (arg_index);
+}
+
+/* Exit the shell with status S. */
+void
+exit_shell (s)
+     int s;
+{
+  fflush (stdout);             /* XXX */
+  fflush (stderr);
+
+#if defined (READLINE)
+  if (RL_ISSTATE (RL_STATE_TERMPREPPED) && rl_deprep_term_function)
+    (*rl_deprep_term_function) ();
+#endif
+
+  /* Do trap[0] if defined.  Allow it to override the exit status
+     passed to us. */
+  if (signal_is_trapped (0))
+    s = run_exit_trap ();
+
+#if defined (PROCESS_SUBSTITUTION)
+  unlink_fifo_list ();
+#endif /* PROCESS_SUBSTITUTION */
+
+#if defined (HISTORY)
+  if (remember_on_history)
+    maybe_save_shell_history ();
+#endif /* HISTORY */
+
+#if defined (COPROCESS_SUPPORT)
+  coproc_flush ();
+#endif
+
+#if defined (JOB_CONTROL)
+  /* If the user has run `shopt -s huponexit', hangup all jobs when we exit
+     an interactive login shell.  ksh does this unconditionally. */
+  if (interactive_shell && login_shell && hup_on_exit)
+    hangup_all_jobs ();
+
+  /* If this shell is interactive, or job control is active, terminate all
+     stopped jobs and restore the original terminal process group.  Don't do
+     this if we're in a subshell and calling exit_shell after, for example,
+     a failed word expansion.  We want to do this even if the shell is not
+     interactive because we set the terminal's process group when job control
+     is enabled regardless of the interactive status. */
+  if (subshell_environment == 0)
+    end_job_control ();
+#endif /* JOB_CONTROL */
+
+  /* Always return the exit status of the last command to our parent. */
+  sh_exit (s);
+}
+
+/* A wrapper for exit that (optionally) can do other things, like malloc
+   statistics tracing. */
+void
+sh_exit (s)
+     int s;
+{
+#if defined (MALLOC_DEBUG) && defined (USING_BASH_MALLOC)
+  if (malloc_trace_at_exit)
+    trace_malloc_stats (get_name_for_error (), (char *)NULL);
+#endif
+
+  exit (s);
+}
+
+/* Exit a subshell, which includes calling the exit trap.  We don't want to
+   do any more cleanup, since a subshell is created as an exact copy of its
+   parent. */
+void
+subshell_exit (s)
+     int s;
+{
+  fflush (stdout);
+  fflush (stderr);
+
+  /* Do trap[0] if defined.  Allow it to override the exit status
+     passed to us. */
+  if (signal_is_trapped (0))
+    s = run_exit_trap ();
+
+  sh_exit (s);
+}
+
+/* Source the bash startup files.  If POSIXLY_CORRECT is non-zero, we obey
+   the Posix.2 startup file rules:  $ENV is expanded, and if the file it
+   names exists, that file is sourced.  The Posix.2 rules are in effect
+   for interactive shells only. (section 4.56.5.3) */
+
+/* Execute ~/.bashrc for most shells.  Never execute it if
+   ACT_LIKE_SH is set, or if NO_RC is set.
+
+   If the executable file "/usr/gnu/src/bash/foo" contains:
+
+   #!/usr/gnu/bin/bash
+   echo hello
+
+   then:
+
+        COMMAND            EXECUTE BASHRC
+        --------------------------------
+        bash -c foo            NO
+        bash foo               NO
+        foo                    NO
+        rsh machine ls         YES (for rsh, which calls `bash -c')
+        rsh machine foo        YES (for shell started by rsh) NO (for foo!)
+        echo ls | bash         NO
+        login                  NO
+        bash                   YES
+*/
+
+static void
+execute_env_file (env_file)
+      char *env_file;
+{
+  char *fn;
+
+  if (env_file && *env_file)
+    {
+      fn = expand_string_unsplit_to_string (env_file, Q_DOUBLE_QUOTES);
+      if (fn && *fn)
+       maybe_execute_file (fn, 1);
+      FREE (fn);
+    }
+}
+
+static void
+run_startup_files ()
+{
+#if defined (JOB_CONTROL)
+  int old_job_control;
+#endif
+  int sourced_login, run_by_ssh;
+
+  /* get the rshd/sshd case out of the way first. */
+  if (interactive_shell == 0 && no_rc == 0 && login_shell == 0 &&
+      act_like_sh == 0 && command_execution_string)
+    {
+#ifdef SSH_SOURCE_BASHRC
+      run_by_ssh = (find_variable ("SSH_CLIENT") != (SHELL_VAR *)0) ||
+                  (find_variable ("SSH2_CLIENT") != (SHELL_VAR *)0);
+#else
+      run_by_ssh = 0;
+#endif
+
+      /* If we were run by sshd or we think we were run by rshd, execute
+        ~/.bashrc if we are a top-level shell. */
+      if ((run_by_ssh || isnetconn (fileno (stdin))) && shell_level < 2)
+       {
+#ifdef SYS_BASHRC
+#  if defined (__OPENNT)
+         maybe_execute_file (_prefixInstallPath(SYS_BASHRC, NULL, 0), 1);
+#  else
+         maybe_execute_file (SYS_BASHRC, 1);
+#  endif
+#endif
+         maybe_execute_file (bashrc_file, 1);
+         return;
+       }
+    }
+
+#if defined (JOB_CONTROL)
+  /* Startup files should be run without job control enabled. */
+  old_job_control = interactive_shell ? set_job_control (0) : 0;
+#endif
+
+  sourced_login = 0;
+
+  /* A shell begun with the --login (or -l) flag that is not in posix mode
+     runs the login shell startup files, no matter whether or not it is
+     interactive.  If NON_INTERACTIVE_LOGIN_SHELLS is defined, run the
+     startup files if argv[0][0] == '-' as well. */
+#if defined (NON_INTERACTIVE_LOGIN_SHELLS)
+  if (login_shell && posixly_correct == 0)
+#else
+  if (login_shell < 0 && posixly_correct == 0)
+#endif
+    {
+      /* We don't execute .bashrc for login shells. */
+      no_rc++;
+
+      /* Execute /etc/profile and one of the personal login shell
+        initialization files. */
+      if (no_profile == 0)
+       {
+         maybe_execute_file (SYS_PROFILE, 1);
+
+         if (act_like_sh)      /* sh */
+           maybe_execute_file ("~/.profile", 1);
+         else if ((maybe_execute_file ("~/.bash_profile", 1) == 0) &&
+                  (maybe_execute_file ("~/.bash_login", 1) == 0))      /* bash */
+           maybe_execute_file ("~/.profile", 1);
+       }
+
+      sourced_login = 1;
+    }
+
+  /* A non-interactive shell not named `sh' and not in posix mode reads and
+     executes commands from $BASH_ENV.  If `su' starts a shell with `-c cmd'
+     and `-su' as the name of the shell, we want to read the startup files.
+     No other non-interactive shells read any startup files. */
+  if (interactive_shell == 0 && !(su_shell && login_shell))
+    {
+      if (posixly_correct == 0 && act_like_sh == 0 && privileged_mode == 0 &&
+           sourced_env++ == 0)
+       execute_env_file (get_string_value ("BASH_ENV"));
+      return;
+    }
+
+  /* Interactive shell or `-su' shell. */
+  if (posixly_correct == 0)              /* bash, sh */
+    {
+      if (login_shell && sourced_login++ == 0)
+       {
+         /* We don't execute .bashrc for login shells. */
+         no_rc++;
+
+         /* Execute /etc/profile and one of the personal login shell
+            initialization files. */
+         if (no_profile == 0)
+           {
+             maybe_execute_file (SYS_PROFILE, 1);
+
+             if (act_like_sh)  /* sh */
+               maybe_execute_file ("~/.profile", 1);
+             else if ((maybe_execute_file ("~/.bash_profile", 1) == 0) &&
+                      (maybe_execute_file ("~/.bash_login", 1) == 0))  /* bash */
+               maybe_execute_file ("~/.profile", 1);
+           }
+       }
+
+      /* bash */
+      if (act_like_sh == 0 && no_rc == 0)
+       {
+#ifdef SYS_BASHRC
+#  if defined (__OPENNT)
+         maybe_execute_file (_prefixInstallPath(SYS_BASHRC, NULL, 0), 1);
+#  else
+         maybe_execute_file (SYS_BASHRC, 1);
+#  endif
+#endif
+         maybe_execute_file (bashrc_file, 1);
+       }
+      /* sh */
+      else if (act_like_sh && privileged_mode == 0 && sourced_env++ == 0)
+       execute_env_file (get_string_value ("ENV"));
+    }
+  else         /* bash --posix, sh --posix */
+    {
+      /* bash and sh */
+      if (interactive_shell && privileged_mode == 0 && sourced_env++ == 0)
+       execute_env_file (get_string_value ("ENV"));
+    }
+
+#if defined (JOB_CONTROL)
+  set_job_control (old_job_control);
+#endif
+}
+
+#if defined (RESTRICTED_SHELL)
+/* Return 1 if the shell should be a restricted one based on NAME or the
+   value of `restricted'.  Don't actually do anything, just return a
+   boolean value. */
+int
+shell_is_restricted (name)
+     char *name;
+{
+  char *temp;
+
+  if (restricted)
+    return 1;
+  temp = base_pathname (name);
+  if (*temp == '-')
+    temp++;
+  return (STREQ (temp, RESTRICTED_SHELL_NAME));
+}
+
+/* Perhaps make this shell a `restricted' one, based on NAME.  If the
+   basename of NAME is "rbash", then this shell is restricted.  The
+   name of the restricted shell is a configurable option, see config.h.
+   In a restricted shell, PATH, SHELL, ENV, and BASH_ENV are read-only
+   and non-unsettable.
+   Do this also if `restricted' is already set to 1; maybe the shell was
+   started with -r. */
+int
+maybe_make_restricted (name)
+     char *name;
+{
+  char *temp;
+
+  temp = base_pathname (name);
+  if (*temp == '-')
+    temp++;
+  if (restricted || (STREQ (temp, RESTRICTED_SHELL_NAME)))
+    {
+      set_var_read_only ("PATH");
+      set_var_read_only ("SHELL");
+      set_var_read_only ("ENV");
+      set_var_read_only ("BASH_ENV");
+      restricted = 1;
+    }
+  return (restricted);
+}
+#endif /* RESTRICTED_SHELL */
+
+/* Fetch the current set of uids and gids and return 1 if we're running
+   setuid or setgid. */
+static int
+uidget ()
+{
+  uid_t u;
+
+  u = getuid ();
+  if (current_user.uid != u)
+    {
+      FREE (current_user.user_name);
+      FREE (current_user.shell);
+      FREE (current_user.home_dir);
+      current_user.user_name = current_user.shell = current_user.home_dir = (char *)NULL;
+    }
+  current_user.uid = u;
+  current_user.gid = getgid ();
+  current_user.euid = geteuid ();
+  current_user.egid = getegid ();
+
+  /* See whether or not we are running setuid or setgid. */
+  return (current_user.uid != current_user.euid) ||
+          (current_user.gid != current_user.egid);
+}
+
+void
+disable_priv_mode ()
+{
+  int e;
+
+  if (setuid (current_user.uid) < 0)
+    {
+      e = errno;
+      sys_error (_("cannot set uid to %d: effective uid %d"), current_user.uid, current_user.euid);
+#if defined (EXIT_ON_SETUID_FAILURE)
+      if (e == EAGAIN)
+       exit (e);
+#endif
+    }
+  if (setgid (current_user.gid) < 0)
+    sys_error (_("cannot set gid to %d: effective gid %d"), current_user.gid, current_user.egid);
+
+  current_user.euid = current_user.uid;
+  current_user.egid = current_user.gid;
+}
+
+#if defined (WORDEXP_OPTION)
+static int
+run_wordexp (words)
+     char *words;
+{
+  int code, nw, nb;
+  WORD_LIST *wl, *tl, *result;
+
+  code = setjmp_nosigs (top_level);
+
+  if (code != NOT_JUMPED)
+    {
+      switch (code)
+       {
+         /* Some kind of throw to top_level has occurred. */
+       case FORCE_EOF:
+         return last_command_exit_value = 127;
+       case ERREXIT:
+       case EXITPROG:
+         return last_command_exit_value;
+       case DISCARD:
+         return last_command_exit_value = 1;
+       default:
+         command_error ("run_wordexp", CMDERR_BADJUMP, code, 0);
+       }
+    }
+
+  /* Run it through the parser to get a list of words and expand them */
+  if (words && *words)
+    {
+      with_input_from_string (words, "--wordexp");
+      if (parse_command () != 0)
+       return (126);
+      if (global_command == 0)
+       {
+         printf ("0\n0\n");
+         return (0);
+       }
+      if (global_command->type != cm_simple)
+       return (126);
+      wl = global_command->value.Simple->words;
+      if (protected_mode)
+       for (tl = wl; tl; tl = tl->next)
+         tl->word->flags |= W_NOCOMSUB|W_NOPROCSUB;
+      result = wl ? expand_words_no_vars (wl) : (WORD_LIST *)0;
+    }
+  else
+    result = (WORD_LIST *)0;
+
+  last_command_exit_value = 0;
+
+  if (result == 0)
+    {
+      printf ("0\n0\n");
+      return (0);
+    }
+
+  /* Count up the number of words and bytes, and print them.  Don't count
+     the trailing NUL byte. */
+  for (nw = nb = 0, wl = result; wl; wl = wl->next)
+    {
+      nw++;
+      nb += strlen (wl->word->word);
+    }
+  printf ("%u\n%u\n", nw, nb);
+  /* Print each word on a separate line.  This will have to be changed when
+     the interface to glibc is completed. */
+  for (wl = result; wl; wl = wl->next)
+    printf ("%s\n", wl->word->word);
+
+  return (0);
+}
+#endif
+
+#if defined (ONESHOT)
+/* Run one command, given as the argument to the -c option.  Tell
+   parse_and_execute not to fork for a simple command. */
+static int
+run_one_command (command)
+     char *command;
+{
+  int code;
+
+  code = setjmp_nosigs (top_level);
+
+  if (code != NOT_JUMPED)
+    {
+#if defined (PROCESS_SUBSTITUTION)
+      unlink_fifo_list ();
+#endif /* PROCESS_SUBSTITUTION */
+      switch (code)
+       {
+         /* Some kind of throw to top_level has occurred. */
+       case FORCE_EOF:
+         return last_command_exit_value = 127;
+       case ERREXIT:
+       case EXITPROG:
+         return last_command_exit_value;
+       case DISCARD:
+         return last_command_exit_value = 1;
+       default:
+         command_error ("run_one_command", CMDERR_BADJUMP, code, 0);
+       }
+    }
+   return (parse_and_execute (savestring (command), "-c", SEVAL_NOHIST));
+}
+#endif /* ONESHOT */
+
+static int
+bind_args (argv, arg_start, arg_end, start_index)
+     char **argv;
+     int arg_start, arg_end, start_index;
+{
+  register int i;
+  WORD_LIST *args;
+
+  for (i = arg_start, args = (WORD_LIST *)NULL; i < arg_end; i++)
+    args = make_word_list (make_word (argv[i]), args);
+  if (args)
+    {
+      args = REVERSE_LIST (args, WORD_LIST *);
+      if (start_index == 0)    /* bind to $0...$n for sh -c command */
+       {
+         /* Posix.2 4.56.3 says that the first argument after sh -c command
+            becomes $0, and the rest of the arguments become $1...$n */
+         shell_name = savestring (args->word->word);
+         FREE (dollar_vars[0]);
+         dollar_vars[0] = savestring (args->word->word);
+         remember_args (args->next, 1);
+         push_args (args->next);       /* BASH_ARGV and BASH_ARGC */
+       }
+      else                     /* bind to $1...$n for shell script */
+        {
+         remember_args (args, 1);
+         push_args (args);             /* BASH_ARGV and BASH_ARGC */
+        }
+
+      dispose_words (args);
+    }
+
+  return (i);
+}
+
+void
+unbind_args ()
+{
+  remember_args ((WORD_LIST *)NULL, 1);
+  pop_args ();                         /* Reset BASH_ARGV and BASH_ARGC */
+}
+
+static void
+start_debugger ()
+{
+#if defined (DEBUGGER) && defined (DEBUGGER_START_FILE)
+  int old_errexit;
+
+  old_errexit = exit_immediately_on_error;
+  exit_immediately_on_error = 0;
+
+  maybe_execute_file (DEBUGGER_START_FILE, 1);
+  function_trace_mode = 1;
+
+  exit_immediately_on_error += old_errexit;
+#endif
+}
+
+static int
+open_shell_script (script_name)
+     char *script_name;
+{
+  int fd, e, fd_is_tty;
+  char *filename, *path_filename, *t;
+  char sample[80];
+  int sample_len;
+  struct stat sb;
+#if defined (ARRAY_VARS)
+  SHELL_VAR *funcname_v, *bash_source_v, *bash_lineno_v;
+  ARRAY *funcname_a, *bash_source_a, *bash_lineno_a;
+#endif
+
+  filename = savestring (script_name);
+
+  fd = open (filename, O_RDONLY);
+  if ((fd < 0) && (errno == ENOENT) && (absolute_program (filename) == 0))
+    {
+      e = errno;
+      /* If it's not in the current directory, try looking through PATH
+        for it. */
+      path_filename = find_path_file (script_name);
+      if (path_filename)
+       {
+         free (filename);
+         filename = path_filename;
+         fd = open (filename, O_RDONLY);
+       }
+      else
+       errno = e;
+    }
+
+  if (fd < 0)
+    {
+      e = errno;
+      file_error (filename);
+      exit ((e == ENOENT) ? EX_NOTFOUND : EX_NOINPUT);
+    }
+
+  free (dollar_vars[0]);
+  dollar_vars[0] = exec_argv0 ? savestring (exec_argv0) : savestring (script_name);
+  if (exec_argv0)
+    {
+      free (exec_argv0);
+      exec_argv0 = (char *)NULL;
+    }
+
+#if defined (ARRAY_VARS)
+  GET_ARRAY_FROM_VAR ("FUNCNAME", funcname_v, funcname_a);
+  GET_ARRAY_FROM_VAR ("BASH_SOURCE", bash_source_v, bash_source_a);
+  GET_ARRAY_FROM_VAR ("BASH_LINENO", bash_lineno_v, bash_lineno_a);
+
+  array_push (bash_source_a, filename);
+  if (bash_lineno_a)
+    {
+      t = itos (executing_line_number ());
+      array_push (bash_lineno_a, t);
+      free (t);
+    }
+  array_push (funcname_a, "main");
+#endif
+
+#ifdef HAVE_DEV_FD
+  fd_is_tty = isatty (fd);
+#else
+  fd_is_tty = 0;
+#endif
+
+  /* Only do this with non-tty file descriptors we can seek on. */
+  if (fd_is_tty == 0 && (lseek (fd, 0L, 1) != -1))
+    {
+      /* Check to see if the `file' in `bash file' is a binary file
+        according to the same tests done by execute_simple_command (),
+        and report an error and exit if it is. */
+      sample_len = read (fd, sample, sizeof (sample));
+      if (sample_len < 0)
+       {
+         e = errno;
+         if ((fstat (fd, &sb) == 0) && S_ISDIR (sb.st_mode))
+           internal_error (_("%s: is a directory"), filename);
+         else
+           {
+             errno = e;
+             file_error (filename);
+           }
+         exit (EX_NOEXEC);
+       }
+      else if (sample_len > 0 && (check_binary_file (sample, sample_len)))
+       {
+         internal_error (_("%s: cannot execute binary file"), filename);
+         exit (EX_BINARY_FILE);
+       }
+      /* Now rewind the file back to the beginning. */
+      lseek (fd, 0L, 0);
+    }
+
+  /* Open the script.  But try to move the file descriptor to a randomly
+     large one, in the hopes that any descriptors used by the script will
+     not match with ours. */
+  fd = move_to_high_fd (fd, 1, -1);
+
+#if defined (BUFFERED_INPUT)
+  default_buffered_input = fd;
+  SET_CLOSE_ON_EXEC (default_buffered_input);
+#else /* !BUFFERED_INPUT */
+  default_input = fdopen (fd, "r");
+
+  if (default_input == 0)
+    {
+      file_error (filename);
+      exit (EX_NOTFOUND);
+    }
+
+  SET_CLOSE_ON_EXEC (fd);
+  if (fileno (default_input) != fd)
+    SET_CLOSE_ON_EXEC (fileno (default_input));
+#endif /* !BUFFERED_INPUT */
+
+  /* Just about the only way for this code to be executed is if something
+     like `bash -i /dev/stdin' is executed. */
+  if (interactive_shell && fd_is_tty)
+    {
+      dup2 (fd, 0);
+      close (fd);
+      fd = 0;
+#if defined (BUFFERED_INPUT)
+      default_buffered_input = 0;
+#else
+      fclose (default_input);
+      default_input = stdin;
+#endif
+    }
+  else if (forced_interactive && fd_is_tty == 0)
+    /* But if a script is called with something like `bash -i scriptname',
+       we need to do a non-interactive setup here, since we didn't do it
+       before. */
+    init_interactive_script ();
+
+  free (filename);
+  return (fd);
+}
+
+/* Initialize the input routines for the parser. */
+static void
+set_bash_input ()
+{
+  /* Make sure the fd from which we are reading input is not in
+     no-delay mode. */
+#if defined (BUFFERED_INPUT)
+  if (interactive == 0)
+    sh_unset_nodelay_mode (default_buffered_input);
+  else
+#endif /* !BUFFERED_INPUT */
+    sh_unset_nodelay_mode (fileno (stdin));
+
+  /* with_input_from_stdin really means `with_input_from_readline' */
+  if (interactive && no_line_editing == 0)
+    with_input_from_stdin ();
+#if defined (BUFFERED_INPUT)
+  else if (interactive == 0)
+    with_input_from_buffered_stream (default_buffered_input, dollar_vars[0]);
+#endif /* BUFFERED_INPUT */
+  else
+    with_input_from_stream (default_input, dollar_vars[0]);
+}
+
+/* Close the current shell script input source and forget about it.  This is
+   extern so execute_cmd.c:initialize_subshell() can call it.  If CHECK_ZERO
+   is non-zero, we close default_buffered_input even if it's the standard
+   input (fd 0). */
+void
+unset_bash_input (check_zero)
+     int check_zero;
+{
+#if defined (BUFFERED_INPUT)
+  if ((check_zero && default_buffered_input >= 0) ||
+      (check_zero == 0 && default_buffered_input > 0))
+    {
+      close_buffered_fd (default_buffered_input);
+      default_buffered_input = bash_input.location.buffered_fd = -1;
+      bash_input.type = st_none;               /* XXX */
+    }
+#else /* !BUFFERED_INPUT */
+  if (default_input)
+    {
+      fclose (default_input);
+      default_input = (FILE *)NULL;
+    }
+#endif /* !BUFFERED_INPUT */
+}
+      
+
+#if !defined (PROGRAM)
+#  define PROGRAM "bash"
+#endif
+
+static void
+set_shell_name (argv0)
+     char *argv0;
+{
+  /* Here's a hack.  If the name of this shell is "sh", then don't do
+     any startup files; just try to be more like /bin/sh. */
+  shell_name = argv0 ? base_pathname (argv0) : PROGRAM;
+
+  if (argv0 && *argv0 == '-')
+    {
+      if (*shell_name == '-')
+       shell_name++;
+      login_shell = 1;
+    }
+
+  if (shell_name[0] == 's' && shell_name[1] == 'h' && shell_name[2] == '\0')
+    act_like_sh++;
+  if (shell_name[0] == 's' && shell_name[1] == 'u' && shell_name[2] == '\0')
+    su_shell++;
+
+  shell_name = argv0 ? argv0 : PROGRAM;
+  FREE (dollar_vars[0]);
+  dollar_vars[0] = savestring (shell_name);
+
+  /* A program may start an interactive shell with
+         "execl ("/bin/bash", "-", NULL)".
+     If so, default the name of this shell to our name. */
+  if (!shell_name || !*shell_name || (shell_name[0] == '-' && !shell_name[1]))
+    shell_name = PROGRAM;
+}
+
+static void
+init_interactive ()
+{
+  expand_aliases = interactive_shell = startup_state = 1;
+  interactive = 1;
+}
+
+static void
+init_noninteractive ()
+{
+#if defined (HISTORY)
+  bash_history_reinit (0);
+#endif /* HISTORY */
+  interactive_shell = startup_state = interactive = 0;
+  expand_aliases = posixly_correct;    /* XXX - was 0 not posixly_correct */
+  no_line_editing = 1;
+#if defined (JOB_CONTROL)
+  /* Even if the shell is not interactive, enable job control if the -i or
+     -m option is supplied at startup. */
+  set_job_control (forced_interactive||jobs_m_flag);
+#endif /* JOB_CONTROL */
+}
+
+static void
+init_interactive_script ()
+{
+  init_noninteractive ();
+  expand_aliases = interactive_shell = startup_state = 1;
+}
+
+void
+get_current_user_info ()
+{
+  struct passwd *entry;
+
+  /* Don't fetch this more than once. */
+  if (current_user.user_name == 0)
+    {
+#if defined (__TANDEM)
+      entry = getpwnam (getlogin ());
+#else
+      entry = getpwuid (current_user.uid);
+#endif
+      if (entry)
+       {
+         current_user.user_name = savestring (entry->pw_name);
+         current_user.shell = (entry->pw_shell && entry->pw_shell[0])
+                               ? savestring (entry->pw_shell)
+                               : savestring ("/bin/sh");
+         current_user.home_dir = savestring (entry->pw_dir);
+       }
+      else
+       {
+         current_user.user_name = _("I have no name!");
+         current_user.user_name = savestring (current_user.user_name);
+         current_user.shell = savestring ("/bin/sh");
+         current_user.home_dir = savestring ("/");
+       }
+      endpwent ();
+    }
+}
+
+/* Do whatever is necessary to initialize the shell.
+   Put new initializations in here. */
+static void
+shell_initialize ()
+{
+  char hostname[256];
+
+  /* Line buffer output for stderr and stdout. */
+  if (shell_initialized == 0)
+    {
+      sh_setlinebuf (stderr);
+      sh_setlinebuf (stdout);
+    }
+
+  /* Sort the array of shell builtins so that the binary search in
+     find_shell_builtin () works correctly. */
+  initialize_shell_builtins ();
+
+  /* Initialize the trap signal handlers before installing our own
+     signal handlers.  traps.c:restore_original_signals () is responsible
+     for restoring the original default signal handlers.  That function
+     is called when we make a new child. */
+  initialize_traps ();
+  initialize_signals (0);
+
+  /* It's highly unlikely that this will change. */
+  if (current_host_name == 0)
+    {
+      /* Initialize current_host_name. */
+      if (gethostname (hostname, 255) < 0)
+       current_host_name = "??host??";
+      else
+       current_host_name = savestring (hostname);
+    }
+
+  /* Initialize the stuff in current_user that comes from the password
+     file.  We don't need to do this right away if the shell is not
+     interactive. */
+  if (interactive_shell)
+    get_current_user_info ();
+
+  /* Initialize our interface to the tilde expander. */
+  tilde_initialize ();
+
+  /* Initialize internal and environment variables.  Don't import shell
+     functions from the environment if we are running in privileged or
+     restricted mode or if the shell is running setuid. */
+#if defined (RESTRICTED_SHELL)
+  initialize_shell_variables (shell_environment, privileged_mode||restricted||running_setuid);
+#else
+  initialize_shell_variables (shell_environment, privileged_mode||running_setuid);
+#endif
+
+  /* Initialize the data structures for storing and running jobs. */
+  initialize_job_control (jobs_m_flag);
+
+  /* Initialize input streams to null. */
+  initialize_bash_input ();
+
+  initialize_flags ();
+
+  /* Initialize the shell options.  Don't import the shell options
+     from the environment variables $SHELLOPTS or $BASHOPTS if we are
+     running in privileged or restricted mode or if the shell is running
+     setuid. */
+#if defined (RESTRICTED_SHELL)
+  initialize_shell_options (privileged_mode||restricted||running_setuid);
+  initialize_bashopts (privileged_mode||restricted||running_setuid);
+#else
+  initialize_shell_options (privileged_mode||running_setuid);
+  initialize_bashopts (privileged_mode||running_setuid);
+#endif
+}
+
+/* Function called by main () when it appears that the shell has already
+   had some initialization performed.  This is supposed to reset the world
+   back to a pristine state, as if we had been exec'ed. */
+static void
+shell_reinitialize ()
+{
+  /* The default shell prompts. */
+  primary_prompt = PPROMPT;
+  secondary_prompt = SPROMPT;
+
+  /* Things that get 1. */
+  current_command_number = 1;
+
+  /* We have decided that the ~/.bashrc file should not be executed
+     for the invocation of each shell script.  If the variable $ENV
+     (or $BASH_ENV) is set, its value is used as the name of a file
+     to source. */
+  no_rc = no_profile = 1;
+
+  /* Things that get 0. */
+  login_shell = make_login_shell = interactive = executing = 0;
+  debugging = do_version = line_number = last_command_exit_value = 0;
+  forced_interactive = interactive_shell = 0;
+  subshell_environment = running_in_background = 0;
+  expand_aliases = 0;
+
+  /* XXX - should we set jobs_m_flag to 0 here? */
+
+#if defined (HISTORY)
+  bash_history_reinit (0);
+#endif /* HISTORY */
+
+#if defined (RESTRICTED_SHELL)
+  restricted = 0;
+#endif /* RESTRICTED_SHELL */
+
+  /* Ensure that the default startup file is used.  (Except that we don't
+     execute this file for reinitialized shells). */
+  bashrc_file = DEFAULT_BASHRC;
+
+  /* Delete all variables and functions.  They will be reinitialized when
+     the environment is parsed. */
+  delete_all_contexts (shell_variables);
+  delete_all_variables (shell_functions);
+
+  reinit_special_variables ();
+
+#if defined (READLINE)
+  bashline_reinitialize ();
+#endif
+
+  shell_reinitialized = 1;
+}
+
+static void
+show_shell_usage (fp, extra)
+     FILE *fp;
+     int extra;
+{
+  int i;
+  char *set_opts, *s, *t;
+
+  if (extra)
+    fprintf (fp, _("GNU bash, version %s-(%s)\n"), shell_version_string (), MACHTYPE);
+  fprintf (fp, _("Usage:\t%s [GNU long option] [option] ...\n\t%s [GNU long option] [option] script-file ...\n"),
+            shell_name, shell_name);
+  fputs (_("GNU long options:\n"), fp);
+  for (i = 0; long_args[i].name; i++)
+    fprintf (fp, "\t--%s\n", long_args[i].name);
+
+  fputs (_("Shell options:\n"), fp);
+  fputs (_("\t-ilrsD or -c command or -O shopt_option\t\t(invocation only)\n"), fp);
+
+  for (i = 0, set_opts = 0; shell_builtins[i].name; i++)
+    if (STREQ (shell_builtins[i].name, "set"))
+      set_opts = savestring (shell_builtins[i].short_doc);
+  if (set_opts)
+    {
+      s = strchr (set_opts, '[');
+      if (s == 0)
+       s = set_opts;
+      while (*++s == '-')
+       ;
+      t = strchr (s, ']');
+      if (t)
+       *t = '\0';
+      fprintf (fp, _("\t-%s or -o option\n"), s);
+      free (set_opts);
+    }
+
+  if (extra)
+    {
+      fprintf (fp, _("Type `%s -c \"help set\"' for more information about shell options.\n"), shell_name);
+      fprintf (fp, _("Type `%s -c help' for more information about shell builtin commands.\n"), shell_name);
+      fprintf (fp, _("Use the `bashbug' command to report bugs.\n"));
+    }
+}
+
+static void
+add_shopt_to_alist (opt, on_or_off)
+     char *opt;
+     int on_or_off;
+{
+  if (shopt_ind >= shopt_len)
+    {
+      shopt_len += 8;
+      shopt_alist = (STRING_INT_ALIST *)xrealloc (shopt_alist, shopt_len * sizeof (shopt_alist[0]));
+    }
+  shopt_alist[shopt_ind].word = opt;
+  shopt_alist[shopt_ind].token = on_or_off;
+  shopt_ind++;
+}
+
+static void
+run_shopt_alist ()
+{
+  register int i;
+
+  for (i = 0; i < shopt_ind; i++)
+    if (shopt_setopt (shopt_alist[i].word, (shopt_alist[i].token == '-')) != EXECUTION_SUCCESS)
+      exit (EX_BADUSAGE);
+  free (shopt_alist);
+  shopt_alist = 0;
+  shopt_ind = shopt_len = 0;
+}
diff --git a/shell.h b/shell.h
index d63dce8cd83fe896dbe98f93903fcd5da4b25077..3cf25df0bd64155ce45f698d15fd696644c23e5c 100644 (file)
--- a/shell.h
+++ b/shell.h
@@ -180,6 +180,8 @@ typedef struct _sh_input_line_state_t {
 } sh_input_line_state_t;
 
 /* Let's try declaring these here. */
+extern char *parser_remaining_input __P((void));
+
 extern sh_parser_state_t *save_parser_state __P((sh_parser_state_t *));
 extern void restore_parser_state __P((sh_parser_state_t *));
 
diff --git a/tests/exportfunc.right b/tests/exportfunc.right
new file mode 100644 (file)
index 0000000..5d889df
--- /dev/null
@@ -0,0 +1,16 @@
+exportfunc ok 1
+exportfunc ok 2
+./exportfunc.tests: line 24: cve7169-bad: No such file or directory
+./exportfunc.tests: eval: line 30: syntax error: unexpected end of file
+./exportfunc.tests: line 30: cve7169-bad2: No such file or directory
+./exportfunc1.sub: line 1: maximum here-document count exceeded
+/usr/local/build/bash/bash-current/bash: warning: here-document at line 0 delimited by end-of-file (wanted `a')
+./exportfunc.tests: line 51: HELLO_WORLD: No such file or directory
+eval ok
+./exportfunc3.sub: line 10: export: foo=bar: cannot export
+status: 1
+equals-1
+/usr/local/build/bash/bash-current/bash: foo=bar: command not found
+bad echo
+./exportfunc3.sub: line 23: export: /bin/echo: cannot export
+bar
diff --git a/tests/exportfunc.tests b/tests/exportfunc.tests
new file mode 100644 (file)
index 0000000..85e2e96
--- /dev/null
@@ -0,0 +1,71 @@
+# normal operation
+foo()
+{
+       echo exportfunc ok 1
+}
+export -f foo
+${THIS_SH} -c foo
+unset -f foo
+foo-a ()
+{
+       echo exportfunc ok 2
+}
+export -f foo-a
+${THIS_SH} -c 'foo-a'
+
+# CVE-2014-6271
+
+env -i BASH_FUNC_foo%%='() { echo cve6271 ok; } ; echo BAD' ${THIS_SH} -c foo 2>/dev/null
+
+# CVE-2014-7169
+
+rm -f cve7169-bad
+env -i BASH_FUNC_X%%='() { (a)=>\' ${THIS_SH} -c cve7169-bad 2>/dev/null
+: < cve7169-bad
+rm -f cve7169-bad
+
+echo cve7169-bad2 > bar
+rm -f cve7169-bad2
+eval  'X() { (a)>\' ; . ./bar 2>/dev/null
+: < cve7169-bad2
+rm -f cve7169-bad2 bar
+
+# CVE-2014-7186
+${THIS_SH} ./exportfunc1.sub
+
+# CVE-2014-7187
+${THIS_SH} ./exportfunc2.sub
+
+# CVE-2014-6277
+
+env BASH_FUNC_foo%%="() { 000(){>0;}&000(){ 0;}<<0 0" ${THIS_SH} -c foo 2>/dev/null
+env BASH_FUNC_foo%%="() { 000(){>0;}&000(){ 0;}<<`perl -e '{print "A"x100000}'` 0" ${THIS_SH} -c foo 2>/dev/null
+${THIS_SH} -c "f(){ x(){ _;}; x(){ _;}<<a;}"
+
+# CVE-2014-6278
+
+env 'BASH_FUNC_FOO%%=() { 0;}>r[0${$(}0 {>"$(id >/dev/tty)"; }' ${THIS_SH} -c : 2>/dev/null
+
+rm -f HELLO_WORLD
+env BASH_FUNC_FOO%%='() { 0;}>r[0${$(}0 {>HELLO_WORLD; }' ${THIS_SH} -c : 2>/dev/null
+: < HELLO_WORLD
+
+env BASH_FUNC_x%%='() { _;}>_[$($())] { echo vuln;}' ${THIS_SH} -c : 2>/dev/null
+
+env -i BASH_FUNC_x%%='() { _; } >_[${ $() }] { id; }' ${THIS_SH} -c : 2>/dev/null
+
+env BASH_FUNC_x%%=$'() { _;}>_[$($())]\n{ echo vuln;}' ${THIS_SH} -c : 2>/dev/null
+eval 'x() { _;}>_[$($())] { echo vuln;}' 2>/dev/null
+
+eval 'foo() { _; } >_[${ $() }] ;{ echo eval ok; }'
+
+# other tests fixed in bash43-030 concerning function name transformation
+env $'BASH_FUNC_\nfoo%%=() { echo transform-1; }' ${THIS_SH} -c foo 2>/dev/null
+env $'BASH_FUNC_foo\n%%=() { echo transform-2; }' ${THIS_SH} -c foo 2>/dev/null
+env $'BASH_FUNC_  foo  %%=() { echo transform-3; }' ${THIS_SH} -c foo 2>/dev/null
+
+unset -f foo
+env $'BASH_FUNC_#badname%%'=$'() { :; }\nfoo () { echo transform-4; }  ' ${THIS_SH} -c 'foo' 2>/dev/null
+
+# tests of exported names
+${THIS_SH} ./exportfunc3.sub
diff --git a/tests/exportfunc.tests~ b/tests/exportfunc.tests~
new file mode 100644 (file)
index 0000000..ec69569
--- /dev/null
@@ -0,0 +1,68 @@
+# normal operation
+foo()
+{
+       echo exportfunc ok 1
+}
+export -f foo
+${THIS_SH} -c foo
+unset -f foo
+foo-a ()
+{
+       echo exportfunc ok 2
+}
+export -f foo-a
+${THIS_SH} -c 'foo-a'
+
+# CVE-2014-6271
+
+env -i BASH_FUNC_foo%%='() { echo cve6271 ok; } ; echo BAD' ${THIS_SH} -c foo 2>/dev/null
+
+# CVE-2014-7169
+
+rm -f cve7169-bad
+env -i BASH_FUNC_X%%='() { (a)=>\' ${THIS_SH} -c cve7169-bad 2>/dev/null
+: < cve7169-bad
+rm -f cve7169-bad
+
+echo cve7169-bad2 > bar
+rm -f cve7169-bad2
+eval  'X() { (a)>\' ; . ./bar 2>/dev/null
+: < cve7169-bad2
+rm -f cve7169-bad2 bar
+
+# CVE-2014-7186
+${THIS_SH} ./exportfunc1.sub
+
+# CVE-2014-7187
+${THIS_SH} ./exportfunc2.sub
+
+# CVE-2014-6277
+
+env BASH_FUNC_foo%%="() { 000(){>0;}&000(){ 0;}<<0 0" ${THIS_SH} -c foo 2>/dev/null
+env BASH_FUNC_foo%%="() { 000(){>0;}&000(){ 0;}<<`perl -e '{print "A"x100000}'` 0" ${THIS_SH} -c foo 2>/dev/null
+${THIS_SH} -c "f(){ x(){ _;}; x(){ _;}<<a;}"
+
+# CVE-2014-6278
+
+env 'BASH_FUNC_FOO%%=() { 0;}>r[0${$(}0 {>"$(id >/dev/tty)"; }' ${THIS_SH} -c : 2>/dev/null
+
+rm -f HELLO_WORLD
+env BASH_FUNC_FOO%%='() { 0;}>r[0${$(}0 {>HELLO_WORLD; }' ${THIS_SH} -c : 2>/dev/null
+: < HELLO_WORLD
+
+env BASH_FUNC_x%%='() { _;}>_[$($())] { echo vuln;}' ${THIS_SH} -c : 2>/dev/null
+
+env -i BASH_FUNC_x%%='() { _; } >_[${ $() }] { id; }' ${THIS_SH} -c : 2>/dev/null
+
+env BASH_FUNC_x%%=$'() { _;}>_[$($())]\n{ echo vuln;}' ${THIS_SH} -c : 2>/dev/null
+eval 'x() { _;}>_[$($())] { echo vuln;}' 2>/dev/null
+
+eval 'foo() { _; } >_[${ $() }] ;{ echo eval ok; }'
+
+# other tests fixed in bash43-030 concerning function name transformation
+env $'BASH_FUNC_\nfoo%%=() { echo transform-1; }' ${THIS_SH} -c foo 2>/dev/null
+env $'BASH_FUNC_foo\n%%=() { echo transform-2; }' ${THIS_SH} -c foo 2>/dev/null
+env $'BASH_FUNC_  foo  %%=() { echo transform-3; }' ${THIS_SH} -c foo 2>/dev/null
+
+unset -f foo
+env $'BASH_FUNC_#badname%%'=$'() { :; }\nfoo () { echo transform-4; }  ' ${THIS_SH} -c 'foo' 2>/dev/null
diff --git a/tests/exportfunc1.sub b/tests/exportfunc1.sub
new file mode 100644 (file)
index 0000000..d9c9fa1
--- /dev/null
@@ -0,0 +1,21 @@
+cat <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF
+EOF
+EOF
+EOF
+EOF
+EOF
+EOF
+EOF
+EOF
+EOF
+EOF
+EOF
+EOF
+EOF
+EOF
+EOF
+EOF
+EOF
+EOF
+
+echo after EOF
diff --git a/tests/exportfunc2.sub b/tests/exportfunc2.sub
new file mode 100644 (file)
index 0000000..886b71b
--- /dev/null
@@ -0,0 +1,400 @@
+for x1 in ; do :
+for x2 in ; do :
+for x3 in ; do :
+for x4 in ; do :
+for x5 in ; do :
+for x6 in ; do :
+for x7 in ; do :
+for x8 in ; do :
+for x9 in ; do :
+for x10 in ; do :
+for x11 in ; do :
+for x12 in ; do :
+for x13 in ; do :
+for x14 in ; do :
+for x15 in ; do :
+for x16 in ; do :
+for x17 in ; do :
+for x18 in ; do :
+for x19 in ; do :
+for x20 in ; do :
+for x21 in ; do :
+for x22 in ; do :
+for x23 in ; do :
+for x24 in ; do :
+for x25 in ; do :
+for x26 in ; do :
+for x27 in ; do :
+for x28 in ; do :
+for x29 in ; do :
+for x30 in ; do :
+for x31 in ; do :
+for x32 in ; do :
+for x33 in ; do :
+for x34 in ; do :
+for x35 in ; do :
+for x36 in ; do :
+for x37 in ; do :
+for x38 in ; do :
+for x39 in ; do :
+for x40 in ; do :
+for x41 in ; do :
+for x42 in ; do :
+for x43 in ; do :
+for x44 in ; do :
+for x45 in ; do :
+for x46 in ; do :
+for x47 in ; do :
+for x48 in ; do :
+for x49 in ; do :
+for x50 in ; do :
+for x51 in ; do :
+for x52 in ; do :
+for x53 in ; do :
+for x54 in ; do :
+for x55 in ; do :
+for x56 in ; do :
+for x57 in ; do :
+for x58 in ; do :
+for x59 in ; do :
+for x60 in ; do :
+for x61 in ; do :
+for x62 in ; do :
+for x63 in ; do :
+for x64 in ; do :
+for x65 in ; do :
+for x66 in ; do :
+for x67 in ; do :
+for x68 in ; do :
+for x69 in ; do :
+for x70 in ; do :
+for x71 in ; do :
+for x72 in ; do :
+for x73 in ; do :
+for x74 in ; do :
+for x75 in ; do :
+for x76 in ; do :
+for x77 in ; do :
+for x78 in ; do :
+for x79 in ; do :
+for x80 in ; do :
+for x81 in ; do :
+for x82 in ; do :
+for x83 in ; do :
+for x84 in ; do :
+for x85 in ; do :
+for x86 in ; do :
+for x87 in ; do :
+for x88 in ; do :
+for x89 in ; do :
+for x90 in ; do :
+for x91 in ; do :
+for x92 in ; do :
+for x93 in ; do :
+for x94 in ; do :
+for x95 in ; do :
+for x96 in ; do :
+for x97 in ; do :
+for x98 in ; do :
+for x99 in ; do :
+for x100 in ; do :
+for x101 in ; do :
+for x102 in ; do :
+for x103 in ; do :
+for x104 in ; do :
+for x105 in ; do :
+for x106 in ; do :
+for x107 in ; do :
+for x108 in ; do :
+for x109 in ; do :
+for x110 in ; do :
+for x111 in ; do :
+for x112 in ; do :
+for x113 in ; do :
+for x114 in ; do :
+for x115 in ; do :
+for x116 in ; do :
+for x117 in ; do :
+for x118 in ; do :
+for x119 in ; do :
+for x120 in ; do :
+for x121 in ; do :
+for x122 in ; do :
+for x123 in ; do :
+for x124 in ; do :
+for x125 in ; do :
+for x126 in ; do :
+for x127 in ; do :
+for x128 in ; do :
+for x129 in ; do :
+for x130 in ; do :
+for x131 in ; do :
+for x132 in ; do :
+for x133 in ; do :
+for x134 in ; do :
+for x135 in ; do :
+for x136 in ; do :
+for x137 in ; do :
+for x138 in ; do :
+for x139 in ; do :
+for x140 in ; do :
+for x141 in ; do :
+for x142 in ; do :
+for x143 in ; do :
+for x144 in ; do :
+for x145 in ; do :
+for x146 in ; do :
+for x147 in ; do :
+for x148 in ; do :
+for x149 in ; do :
+for x150 in ; do :
+for x151 in ; do :
+for x152 in ; do :
+for x153 in ; do :
+for x154 in ; do :
+for x155 in ; do :
+for x156 in ; do :
+for x157 in ; do :
+for x158 in ; do :
+for x159 in ; do :
+for x160 in ; do :
+for x161 in ; do :
+for x162 in ; do :
+for x163 in ; do :
+for x164 in ; do :
+for x165 in ; do :
+for x166 in ; do :
+for x167 in ; do :
+for x168 in ; do :
+for x169 in ; do :
+for x170 in ; do :
+for x171 in ; do :
+for x172 in ; do :
+for x173 in ; do :
+for x174 in ; do :
+for x175 in ; do :
+for x176 in ; do :
+for x177 in ; do :
+for x178 in ; do :
+for x179 in ; do :
+for x180 in ; do :
+for x181 in ; do :
+for x182 in ; do :
+for x183 in ; do :
+for x184 in ; do :
+for x185 in ; do :
+for x186 in ; do :
+for x187 in ; do :
+for x188 in ; do :
+for x189 in ; do :
+for x190 in ; do :
+for x191 in ; do :
+for x192 in ; do :
+for x193 in ; do :
+for x194 in ; do :
+for x195 in ; do :
+for x196 in ; do :
+for x197 in ; do :
+for x198 in ; do :
+for x199 in ; do :
+for x200 in ; do :
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
+done
diff --git a/tests/exportfunc3.sub b/tests/exportfunc3.sub
new file mode 100644 (file)
index 0000000..4b52d1c
--- /dev/null
@@ -0,0 +1,25 @@
+# test function names that cannot be exported
+
+unset foo              # remove from environment if necessary
+
+function foo=bar
+{
+       echo equals-1
+}
+
+export -f 'foo=bar'
+echo status: $?
+
+foo\=bar
+printenv | grep 'foo=bar'
+${THIS_SH} -c 'foo\=bar'
+
+function /bin/echo
+{
+       echo bad echo
+}
+
+/bin/echo foo
+export -f '/bin/echo'
+
+${THIS_SH} -c '/bin/echo bar'
diff --git a/tests/run-exportfunc b/tests/run-exportfunc
new file mode 100644 (file)
index 0000000..ef8fbe8
--- /dev/null
@@ -0,0 +1,2 @@
+${THIS_SH} ./exportfunc.tests > /tmp/xx 2>&1
+diff /tmp/xx exportfunc.right && rm -f /tmp/xx
diff --git a/trap.c~ b/trap.c~
index 21553e7c65f4d775e4e6c5b11fca4c9a5e13bd60..9fd2123487b624ff672dbbf11308eeb239012021 100644 (file)
--- a/trap.c~
+++ b/trap.c~
@@ -424,6 +424,7 @@ trap_handler (sig)
       SIGRETURN (0);
     }
 
+itrace("trap_handler: received %d", sig);
   if ((sig >= NSIG) ||
       (trap_list[sig] == (char *)DEFAULT_SIG) ||
       (trap_list[sig] == (char *)IGNORE_SIG))
@@ -857,7 +858,9 @@ run_exit_trap ()
        retval = trap_saved_exit_value;
 
       running_trap = 0;
+#if defined (ARRAY_VARS)
       array_dispose (ps);
+#endif
 
       return retval;
     }
index 11c22887a8c7d242398f42cbc2d1c13490b50a87..e1a4d789124d77072969d9d9f04b1afeaf8b4c09 100644 (file)
@@ -380,10 +380,12 @@ initialize_shell_variables (env, privmode)
          memcpy (temp_string + namelen + 1, string, string_length + 1);
 
          /* Don't import function names that are invalid identifiers from the
-            environment, though we still allow them to be defined as shell
-            variables. */
+            environment in posix mode, though we still allow them to be defined as
+            shell variables. */
          if (absolute_program (tname) == 0 && (posixly_correct == 0 || legal_identifier (tname)))
            parse_and_execute (temp_string, tname, SEVAL_NONINT|SEVAL_NOHIST|SEVAL_FUNCDEF|SEVAL_ONECMD);
+         else
+           free (temp_string);         /* parse_and_execute does this */
 
          if (temp_var = find_function (tname))
            {
index 3fa4aeb2f236496a58c404497a09345b5e2b1641..cc77bd62e0bde94796c9e4a494121611b57558a1 100644 (file)
--- a/version.c
+++ b/version.c
@@ -1,6 +1,6 @@
 /* version.c -- distribution and version numbers. */
 
-/* Copyright (C) 1989-2013 Free Software Foundation, Inc.
+/* Copyright (C) 1989-2014 Free Software Foundation, Inc.
 
    This file is part of GNU Bash, the Bourne Again SHell.
 
@@ -43,7 +43,7 @@ const char * const release_status = (char *)0;
 #endif
 const char * const sccs_version = SCCSVERSION;
 
-const char * const bash_copyright = N_("Copyright (C) 2013 Free Software Foundation, Inc.");
+const char * const bash_copyright = N_("Copyright (C) 2014 Free Software Foundation, Inc.");
 const char * const bash_license = N_("License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\n");
 
 /* If == 31, shell compatible with bash-3.1, == 32 with bash-3.2, and so on */
index 1e011a05ac5d262c45a17cb6db8fd88cbb013d31..cc77bd62e0bde94796c9e4a494121611b57558a1 100644 (file)
@@ -1,6 +1,6 @@
 /* version.c -- distribution and version numbers. */
 
-/* Copyright (C) 1989-2012 Free Software Foundation, Inc.
+/* Copyright (C) 1989-2014 Free Software Foundation, Inc.
 
    This file is part of GNU Bash, the Bourne Again SHell.
 
@@ -43,7 +43,7 @@ const char * const release_status = (char *)0;
 #endif
 const char * const sccs_version = SCCSVERSION;
 
-const char * const bash_copyright = N_("Copyright (C) 2012 Free Software Foundation, Inc.");
+const char * const bash_copyright = N_("Copyright (C) 2014 Free Software Foundation, Inc.");
 const char * const bash_license = N_("License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\n");
 
 /* If == 31, shell compatible with bash-3.1, == 32 with bash-3.2, and so on */