summaryrefslogtreecommitdiff
path: root/builtins
diff options
context:
space:
mode:
authorStephen Hemminger <stephen.hemminger@vyatta.com>2010-10-11 14:49:26 -0700
committerStephen Hemminger <stephen.hemminger@vyatta.com>2010-10-11 15:19:40 -0700
commit011c1d1c0766c65517ebd495465c99e86edb63ec (patch)
tree30d8f6a13235af90897c3223554871ef52225462 /builtins
parent40cfaccf7b178b6239b5cd0013ef80b7ff8e503e (diff)
downloadvyatta-bash-011c1d1c0766c65517ebd495465c99e86edb63ec.tar.gz
vyatta-bash-011c1d1c0766c65517ebd495465c99e86edb63ec.zip
Update to bash-4.1
Diffstat (limited to 'builtins')
-rw-r--r--builtins/Makefile.in134
-rw-r--r--builtins/alias.def50
-rw-r--r--builtins/bashgetopt.c24
-rw-r--r--builtins/bashgetopt.h26
-rw-r--r--builtins/bind.def76
-rw-r--r--builtins/break.def49
-rw-r--r--builtins/builtin.def35
-rw-r--r--builtins/caller.def54
-rw-r--r--builtins/cd.def121
-rw-r--r--builtins/colon.def36
-rw-r--r--builtins/command.def84
-rw-r--r--builtins/common.c160
-rw-r--r--builtins/common.h37
-rw-r--r--builtins/complete.def349
-rw-r--r--builtins/declare.def219
-rw-r--r--builtins/echo.def90
-rw-r--r--builtins/enable.def61
-rw-r--r--builtins/eval.def31
-rw-r--r--builtins/evalfile.c73
-rw-r--r--builtins/evalstring.c258
-rw-r--r--builtins/exec.def49
-rw-r--r--builtins/exit.def74
-rw-r--r--builtins/fc.def105
-rw-r--r--builtins/fg_bg.def47
-rw-r--r--builtins/getopt.c21
-rw-r--r--builtins/getopt.h21
-rw-r--r--builtins/getopts.def30
-rw-r--r--builtins/hash.def56
-rw-r--r--builtins/help.def264
-rw-r--r--builtins/history.def135
-rw-r--r--builtins/inlib.def28
-rw-r--r--builtins/jobs.def70
-rw-r--r--builtins/kill.def53
-rw-r--r--builtins/let.def39
-rw-r--r--builtins/mapfile.def351
-rw-r--r--builtins/mkbuiltins.c72
-rw-r--r--builtins/printf.def203
-rw-r--r--builtins/psize.c20
-rw-r--r--builtins/pushd.def214
-rw-r--r--builtins/read.def386
-rw-r--r--builtins/reserved.def149
-rw-r--r--builtins/return.def38
-rw-r--r--builtins/set.def214
-rw-r--r--builtins/setattr.def151
-rw-r--r--builtins/shift.def33
-rw-r--r--builtins/shopt.def261
-rw-r--r--builtins/source.def62
-rw-r--r--builtins/suspend.def36
-rw-r--r--builtins/test.def118
-rw-r--r--builtins/times.def34
-rw-r--r--builtins/trap.def64
-rw-r--r--builtins/type.def82
-rw-r--r--builtins/ulimit.def132
-rw-r--r--builtins/umask.def47
-rw-r--r--builtins/wait.def56
55 files changed, 3912 insertions, 1770 deletions
diff --git a/builtins/Makefile.in b/builtins/Makefile.in
index e027f7a..42f8cb8 100644
--- a/builtins/Makefile.in
+++ b/builtins/Makefile.in
@@ -1,20 +1,19 @@
# This Makefile for building libbuiltins.a is in -*- text -*- for Emacs.
#
-# Copyright (C) 1996-2005 Free Software Foundation, Inc.
+# Copyright (C) 1996-2009 Free Software Foundation, Inc.
-# This program 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 2, or (at your option)
-# any later version.
+# This program 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.
-# This program 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.
+# This program 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 this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
PACKAGE = @PACKAGE_NAME@
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
@@ -39,9 +38,12 @@ prefix = @prefix@
srcdir = @srcdir@
VPATH = .:@srcdir@
topdir = @top_srcdir@
+
+datarootdir = @datarootdir@
+
includedir = @includedir@
datadir = @datadir@
-localedir = $(datadir)/locale
+localedir = @localedir@
# Support an alternate destination root directory for package building
DESTDIR =
@@ -63,7 +65,7 @@ LOCAL_DEFS = @LOCAL_DEFS@
LIBS = @LIBS@
LDFLAGS = @LDFLAGS@ $(LOCAL_LDFLAGS) $(CFLAGS)
-LDFLAGS_FOR_BUILD = $(LDFLAGS)
+LDFLAGS_FOR_BUILD = @LDFLAGS_FOR_BUILD@ $(LOCAL_LDFLAGS) $(CFLAGS_FOR_BUILD)
LOCAL_LDFLAGS = @LOCAL_LDFLAGS@
#LIBS_FOR_BUILD = @LIBS_FOR_BUILD@
LIBS_FOR_BUILD = $(LIBS)
@@ -74,7 +76,10 @@ RL_INCLUDEDIR = @RL_INCLUDEDIR@
INTL_LIBSRC = ${topdir}/lib/intl
INTL_BUILDDIR = ${LIBBUILD}/intl
+INTL_LIBDIR = ${INTL_BUILDDIR}
+INTL_LIBRARY = ${INTL_BUILDDIR}/libintl.a
INTL_INC = @INTL_INC@
+INTL_DEP = @INTL_DEP@
LIBINTL_H = @LIBINTL_H@
HELPDIR = @HELPDIR@
@@ -134,7 +139,7 @@ DEFSRC = $(srcdir)/alias.def $(srcdir)/bind.def $(srcdir)/break.def \
$(srcdir)/times.def $(srcdir)/trap.def $(srcdir)/type.def \
$(srcdir)/ulimit.def $(srcdir)/umask.def $(srcdir)/wait.def \
$(srcdir)/reserved.def $(srcdir)/pushd.def $(srcdir)/shopt.def \
- $(srcdir)/printf.def $(srcdir)/complete.def
+ $(srcdir)/printf.def $(srcdir)/complete.def $(srcdir)/mapfile.def
STATIC_SOURCE = common.c evalstring.c evalfile.c getopt.c bashgetopt.c \
getopt.h
@@ -142,8 +147,8 @@ STATIC_SOURCE = common.c evalstring.c evalfile.c getopt.c bashgetopt.c \
OFILES = builtins.o \
alias.o bind.o break.o builtin.o caller.o cd.o colon.o command.o \
common.o declare.o echo.o enable.o eval.o evalfile.o \
- evalstring.o exec.o \
- exit.o fc.o fg_bg.o hash.o help.o history.o jobs.o kill.o let.o \
+ evalstring.o exec.o exit.o fc.o fg_bg.o hash.o help.o history.o \
+ jobs.o kill.o let.o mapfile.o \
pushd.o read.o return.o set.o setattr.o shift.o source.o \
suspend.o test.o times.o trap.o type.o ulimit.o umask.o \
wait.o getopts.o shopt.o printf.o getopt.o bashgetopt.o complete.o
@@ -236,6 +241,11 @@ $(OFILES): $(MKBUILTINS) ../config.h
po: builtins.c
xgettext -L C -o $(topdir)/po/builtins.pot --keyword='N_' builtins.c 2>/dev/null
+${LIBINTL_H}:
+ @echo making $@ in ${INTL_BUILDDIR}
+ @(cd ${INTL_BUILDDIR} && \
+ $(MAKE) $(MFLAGS) libintl.h) || exit 1
+
# dependencies
alias.o: alias.def
@@ -260,6 +270,7 @@ history.o: history.def
jobs.o: jobs.def
kill.o: kill.def
let.o: let.def
+mapfile.o: mapfile.def
printf.o: printf.def
pushd.o: pushd.def
read.o: read.def
@@ -322,7 +333,7 @@ evalstring.o: $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h $(topdir)/subst.h
evalstring.o: $(topdir)/externs.h $(topdir)/jobs.h $(topdir)/builtins.h
evalstring.o: $(topdir)/flags.h $(topdir)/input.h $(topdir)/execute_cmd.h
evalstring.o: $(topdir)/bashhist.h $(srcdir)/common.h
-evalstring.o: $(topdir)/trap.h $(topdir)/redir.h
+evalstring.o: $(topdir)/trap.h $(topdir)/redir.h ../pathnames.h
getopt.o: ../config.h $(BASHINCDIR)/memalloc.h
getopt.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/bashjmp.h $(topdir)/command.h
getopt.o: $(topdir)/general.h $(topdir)/xmalloc.h $(topdir)/error.h $(topdir)/variables.h $(topdir)/conftypes.h
@@ -340,63 +351,67 @@ alias.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h $(BASHINCDIR)
alias.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h
alias.o: $(topdir)/subst.h $(topdir)/externs.h $(srcdir)/common.h
alias.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
+alias.o: ../pathnames.h
bind.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h $(topdir)/error.h
bind.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h
bind.o: $(topdir)/subst.h $(topdir)/externs.h $(srcdir)/bashgetopt.h
bind.o: $(topdir)/general.h $(topdir)/xmalloc.h $(BASHINCDIR)/maxpath.h $(topdir)/bashline.h
bind.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
+bind.o: ../pathnames.h
break.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h
break.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h
break.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h
break.o: $(topdir)/subst.h $(topdir)/externs.h $(BASHINCDIR)/maxpath.h
break.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
+break.o: ../pathnames.h
builtin.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h
builtin.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h $(topdir)/externs.h
builtin.o: $(topdir)/quit.h $(srcdir)/common.h $(BASHINCDIR)/maxpath.h
builtin.o: $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h $(topdir)/subst.h
builtin.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
-builtin.o: $(srcdir)/bashgetopt.h
+builtin.o: $(srcdir)/bashgetopt.h ../pathnames.h
caller.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h $(topdir)/error.h
caller.o: $(topdir)/general.h $(topdir)/xmalloc.h $(topdir)/quit.h $(topdir)/dispose_cmd.h
caller.o: $(topdir)/make_cmd.h $(topdir)/subst.h $(topdir)/externs.h
caller.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
caller.o: $(srcdir)/common.h $(BASHINCDIR)/maxpath.h ./builtext.h
-caller.o: ${BASHINCDIR}/chartypes.h $(topdir)/bashtypes.h
+caller.o: ${BASHINCDIR}/chartypes.h $(topdir)/bashtypes.h ../pathnames.h
cd.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h $(topdir)/error.h
cd.o: $(topdir)/general.h $(topdir)/xmalloc.h $(topdir)/quit.h $(topdir)/dispose_cmd.h
cd.o: $(topdir)/make_cmd.h $(topdir)/subst.h $(topdir)/externs.h
cd.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
-cd.o: $(srcdir)/common.h $(BASHINCDIR)/maxpath.h
+cd.o: $(srcdir)/common.h $(BASHINCDIR)/maxpath.h ../pathnames.h
command.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h
command.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h $(topdir)/externs.h
command.o: $(topdir)/quit.h $(srcdir)/bashgetopt.h $(BASHINCDIR)/maxpath.h
command.o: $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h $(topdir)/subst.h
command.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
+command.o: ../pathnames.h
declare.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h
declare.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h
declare.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h
declare.o: $(topdir)/subst.h $(topdir)/externs.h $(BASHINCDIR)/maxpath.h
declare.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
declare.o: $(topdir)/arrayfunc.h $(srcdir)/bashgetopt.h
-declare.o: ./builtext.h
+declare.o: ./builtext.h ../pathnames.h
echo.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h $(topdir)/error.h
echo.o: $(topdir)/general.h $(topdir)/xmalloc.h $(topdir)/subst.h $(topdir)/externs.h
echo.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h
echo.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
-echo.o: $(BASHINCDIR)/maxpath.h
+echo.o: $(BASHINCDIR)/maxpath.h ../pathnames.h
enable.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h
enable.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h
enable.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h
enable.o: $(topdir)/subst.h $(topdir)/externs.h
enable.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
-enable.o: $(BASHINCDIR)/maxpath.h
+enable.o: $(BASHINCDIR)/maxpath.h ../pathnames.h
enable.o: $(topdir)/pcomplete.h
eval.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h
eval.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h
eval.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h
eval.o: $(topdir)/subst.h $(topdir)/externs.h
eval.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
-eval.o: $(BASHINCDIR)/maxpath.h
+eval.o: $(BASHINCDIR)/maxpath.h ../pathnames.h
exec.o: $(topdir)/bashtypes.h
exec.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h
exec.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h
@@ -404,14 +419,14 @@ exec.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h
exec.o: $(topdir)/subst.h $(topdir)/externs.h $(topdir)/flags.h
exec.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
exec.o: $(srcdir)/common.h $(topdir)/execute_cmd.h $(BASHINCDIR)/maxpath.h
-exec.o: $(topdir)/findcmd.h $(topdir)/jobs.h
+exec.o: $(topdir)/findcmd.h $(topdir)/jobs.h ../pathnames.h
exit.o: $(topdir)/bashtypes.h
exit.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h
exit.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h
exit.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h
exit.o: $(topdir)/subst.h $(topdir)/externs.h $(topdir)/jobs.h
exit.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
-exit.o: $(BASHINCDIR)/maxpath.h ./builtext.h
+exit.o: $(BASHINCDIR)/maxpath.h ./builtext.h ../pathnames.h
fc.o: $(topdir)/bashtypes.h $(BASHINCDIR)/posixstat.h
fc.o: $(topdir)/builtins.h $(topdir)/command.h $(srcdir)/bashgetopt.h
fc.o: $(topdir)/bashhist.h
@@ -421,30 +436,32 @@ fc.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h
fc.o: $(topdir)/subst.h $(topdir)/externs.h $(topdir)/shell.h $(topdir)/syntax.h
fc.o: $(topdir)/flags.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
fc.o: $(topdir)/bashansi.h $(BASHINCDIR)/ansi_stdlib.h $(BASHINCDIR)/chartypes.h
+fc.o: ../pathnames.h
fg_bg.o: $(topdir)/bashtypes.h $(srcdir)/bashgetopt.h
fg_bg.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h
fg_bg.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h
fg_bg.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h
fg_bg.o: $(topdir)/subst.h $(topdir)/externs.h $(BASHINCDIR)/maxpath.h
fg_bg.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
-fg_bg.o: $(topdir)/jobs.h
+fg_bg.o: $(topdir)/jobs.h ../pathnames.h
getopts.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h
getopts.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h
getopts.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h
getopts.o: $(topdir)/subst.h $(topdir)/externs.h $(BASHINCDIR)/maxpath.h
getopts.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
+getopts.o: ../pathnames.h
hash.o: $(topdir)/builtins.h $(topdir)/command.h $(topdir)/quit.h
hash.o: $(topdir)/findcmd.h $(topdir)/hashlib.h
hash.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h
hash.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h
hash.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
-hash.o: $(srcdir)/common.h $(BASHINCDIR)/maxpath.h
+hash.o: $(srcdir)/common.h $(BASHINCDIR)/maxpath.h ../pathnames.h
help.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h
help.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h
help.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h
help.o: $(topdir)/subst.h $(topdir)/externs.h $(BASHINCDIR)/maxpath.h
help.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
-help.o: ${srcdir}/common.h
+help.o: ${srcdir}/common.h ../pathnames.h
history.o: $(topdir)/bashtypes.h
history.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h
history.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h
@@ -452,27 +469,30 @@ history.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h
history.o: $(topdir)/subst.h $(topdir)/externs.h
history.o: ${BASHINCDIR}/filecntl.h $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h
history.o: $(topdir)/variables.h $(topdir)/conftypes.h $(topdir)/bashhist.h $(BASHINCDIR)/maxpath.h
+history.o: ../pathnames.h
inlib.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h
inlib.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h
inlib.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
inlib.o: $(BASHINCDIR)/maxpath.h $(topdir)/subst.h $(topdir)/externs.h
-inlib.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h
+inlib.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h ../pathnames.h
jobs.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h $(topdir)/error.h
jobs.o: $(topdir)/general.h $(topdir)/xmalloc.h $(topdir)/quit.h $(srcdir)/bashgetopt.h
jobs.o: $(BASHINCDIR)/maxpath.h $(topdir)/externs.h $(topdir)/jobs.h
jobs.o: $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h $(topdir)/subst.h
jobs.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
+jobs.o: ../pathnames.h
kill.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h $(topdir)/error.h
kill.o: $(topdir)/general.h $(topdir)/xmalloc.h $(topdir)/subst.h $(topdir)/externs.h
kill.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h
kill.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/trap.h $(topdir)/unwind_prot.h
kill.o: $(topdir)/variables.h $(topdir)/conftypes.h $(BASHINCDIR)/maxpath.h
-kill.o: $(topdir)/jobs.h
+kill.o: $(topdir)/jobs.h ../pathnames.h
let.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h
let.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h
let.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h
let.o: $(topdir)/subst.h $(topdir)/externs.h $(BASHINCDIR)/maxpath.h
let.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
+let.o: ../pathnames.h
printf.o: ../config.h $(BASHINCDIR)/memalloc.h $(topdir)/bashjmp.h
printf.o: $(topdir)/command.h $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h
printf.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h
@@ -480,110 +500,123 @@ printf.o: $(topdir)/subst.h $(topdir)/externs.h $(topdir)/sig.h
printf.o: ../pathnames.h $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h
printf.o: $(topdir)/variables.h $(topdir)/conftypes.h $(BASHINCDIR)/stdc.h $(srcdir)/bashgetopt.h
printf.o: $(topdir)/bashtypes.h ${srcdir}/common.h $(BASHINCDIR)/chartypes.h
+printf.o: ../pathnames.h
pushd.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h
pushd.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h
pushd.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h
pushd.o: $(topdir)/subst.h $(topdir)/externs.h
pushd.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
pushd.o: $(BASHINCDIR)/maxpath.h $(srcdir)/common.h ./builtext.h
+pushd.o: ../pathnames.h
read.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h
read.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h
read.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h
read.o: $(topdir)/subst.h $(topdir)/externs.h $(BASHINCDIR)/maxpath.h
read.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
read.o: $(BASHINCDIR)/shtty.h
-read.o: $(topdir)/arrayfunc.h
+read.o: $(topdir)/arrayfunc.h ../pathnames.h
return.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h
return.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h
return.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h
return.o: $(topdir)/subst.h $(topdir)/externs.h $(BASHINCDIR)/maxpath.h
return.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
+return.o: ../pathnames.h
set.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h
set.o: $(topdir)/general.h $(topdir)/xmalloc.h $(topdir)/subst.h $(topdir)/externs.h
set.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h
set.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
set.o: $(BASHINCDIR)/maxpath.h $(topdir)/error.h
-set.o: $(topdir)/arrayfunc.h
+set.o: $(topdir)/arrayfunc.h ../pathnames.h
setattr.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h
setattr.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h $(BASHINCDIR)/maxpath.h
setattr.o: $(topdir)/quit.h $(srcdir)/common.h $(srcdir)/bashgetopt.h
setattr.o: $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h $(topdir)/subst.h
setattr.o: $(topdir)/externs.h
setattr.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
-setattr.o: $(topdir)/arrayfunc.h
+setattr.o: $(topdir)/arrayfunc.h ../pathnames.h
shift.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h
shift.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h
shift.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h
shift.o: $(topdir)/subst.h $(topdir)/externs.h $(BASHINCDIR)/maxpath.h
shift.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
+shift.o: ../pathnames.h
+shopt.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h
+shopt.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h
+shopt.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h
+shopt.o: $(topdir)/subst.h $(topdir)/externs.h $(BASHINCDIR)/maxpath.h
+shopt.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
+shopt.o: $(srcdir)/common.h $(srcdir)/bashgetopt.h ../pathnames.h
+shopt.o: $(topdir)/bashhist.h
source.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h
source.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h $(topdir)/findcmd.h
source.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h
source.o: $(topdir)/subst.h $(topdir)/externs.h $(BASHINCDIR)/maxpath.h
source.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
source.o: $(srcdir)/bashgetopt.h $(topdir)/flags.h $(topdir)/trap.h
+source.o: ../pathnames.h
suspend.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h
suspend.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h
suspend.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h
suspend.o: $(topdir)/subst.h $(topdir)/externs.h $(BASHINCDIR)/maxpath.h
suspend.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
-suspend.o: $(topdir)/jobs.h
+suspend.o: $(topdir)/jobs.h ../pathnames.h
test.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h
test.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h
test.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h
test.o: $(topdir)/subst.h $(topdir)/externs.h $(BASHINCDIR)/maxpath.h
test.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
-test.o: $(topdir)/test.h
+test.o: $(topdir)/test.h ../pathnames.h
times.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h
times.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h
times.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h
times.o: $(topdir)/subst.h $(topdir)/externs.h $(BASHINCDIR)/maxpath.h
times.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
-times.o: $(BASHINCDIR)/posixtime.h
+times.o: $(BASHINCDIR)/posixtime.h ../pathnames.h
trap.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h
trap.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h $(topdir)/externs.h
trap.o: $(topdir)/quit.h $(srcdir)/common.h $(BASHINCDIR)/maxpath.h
trap.o: $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h $(topdir)/subst.h
trap.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
-trap.o: $(topdir)/findcmd.h
+trap.o: $(topdir)/findcmd.h ../pathnames.h
type.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h
type.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h
type.o: $(topdir)/quit.h $(srcdir)/common.h $(BASHINCDIR)/maxpath.h
type.o: $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h $(topdir)/subst.h
-type.o: $(topdir)/externs.h $(topdir)/hashcmd.h
+type.o: $(topdir)/externs.h $(topdir)/hashcmd.h ../pathnames.h
type.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
ulimit.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h
ulimit.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h
ulimit.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h
ulimit.o: $(topdir)/subst.h $(topdir)/externs.h $(BASHINCDIR)/maxpath.h
ulimit.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
+ulimit.o: ../pathnames.h
umask.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h
umask.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h
umask.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h
umask.o: $(topdir)/subst.h $(topdir)/externs.h $(BASHINCDIR)/maxpath.h
umask.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
-umask.o: $(BASHINCDIR)/chartypes.h
+umask.o: $(BASHINCDIR)/chartypes.h ../pathnames.h
wait.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h
wait.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h
wait.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h
wait.o: $(topdir)/subst.h $(topdir)/externs.h $(BASHINCDIR)/maxpath.h
wait.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
wait.o: $(topdir)/jobs.h
-wait.o: $(BASHINCDIR)/chartypes.h
-shopt.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h
-shopt.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h
-shopt.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h
-shopt.o: $(topdir)/subst.h $(topdir)/externs.h $(BASHINCDIR)/maxpath.h
-shopt.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
-shopt.o: $(srcdir)/common.h $(srcdir)/bashgetopt.h
+wait.o: $(BASHINCDIR)/chartypes.h ../pathnames.h
-complete.o: ../config.h
+complete.o: ../config.h ../pathnames.h
complete.o: ${topdir}/shell.h $(topdir)/syntax.h ${topdir}/bashjmp.h ${BASHINCDIR}/posixjmp.h ${topdir}/sig.h
complete.o: ${topdir}/unwind_prot.h ${topdir}/variables.h
complete.o: ${topdir}/bashtypes.h ${topdir}/bashansi.h ${BASHINCDIR}/ansi_stdlib.h
complete.o: ${topdir}/builtins.h
complete.o: ${topdir}/pcomplete.h
complete.o: ${srcdir}/common.h ${srcdir}/bashgetopt.h
+mapfile.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h
+mapfile.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h
+mapfile.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h
+mapfile.o: $(topdir)/subst.h $(topdir)/externs.h $(BASHINCDIR)/maxpath.h
+mapfile.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/variables.h $(topdir)/conftypes.h
+mapfile.o: $(topdir)/arrayfunc.h ../pathnames.h
#bind.o: $(RL_LIBSRC)chardefs.h $(RL_LIBSRC)readline.h $(RL_LIBSRC)keymaps.h
@@ -609,7 +642,8 @@ inlib.o: ${topdir}/bashintl.h ${LIBINTL_H} $(BASHINCDIR)/gettext.h
jobs.o: ${topdir}/bashintl.h ${LIBINTL_H} $(BASHINCDIR)/gettext.h
kill.o: ${topdir}/bashintl.h ${LIBINTL_H} $(BASHINCDIR)/gettext.h
let.o: ${topdir}/bashintl.h ${LIBINTL_H} $(BASHINCDIR)/gettext.h
-mkbuiltins.c: ${topdir}/bashintl.h ${LIBINTL_H} $(BASHINCDIR)/gettext.h
+mapfile.o: ${topdir}/bashintl.h ${LIBINTL_H} $(BASHINCDIR)/gettext.h
+mkbuiltins.o: ${topdir}/bashintl.h ${LIBINTL_H} $(BASHINCDIR)/gettext.h
printf.o: ${topdir}/bashintl.h ${LIBINTL_H} $(BASHINCDIR)/gettext.h
pushd.o: ${topdir}/bashintl.h ${LIBINTL_H} $(BASHINCDIR)/gettext.h
read.o: ${topdir}/bashintl.h ${LIBINTL_H} $(BASHINCDIR)/gettext.h
diff --git a/builtins/alias.def b/builtins/alias.def
index 572910b..d760ceb 100644
--- a/builtins/alias.def
+++ b/builtins/alias.def
@@ -1,35 +1,43 @@
This file is alias.def, from which is created alias.c
It implements the builtins "alias" and "unalias" in Bash.
-Copyright (C) 1987-2004 Free Software Foundation, Inc.
+Copyright (C) 1987-2009 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 2, or (at your option) any later
-version.
+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.
+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; see the file COPYING. If not, write to the Free Software
-Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
+You should have received a copy of the GNU General Public License
+along with Bash. If not, see <http://www.gnu.org/licenses/>.
$BUILTIN alias
$FUNCTION alias_builtin
$DEPENDS_ON ALIAS
$PRODUCES alias.c
$SHORT_DOC alias [-p] [name[=value] ... ]
-`alias' with no arguments or with the -p option prints the list
-of aliases in the form alias NAME=VALUE on standard output.
+Define or display aliases.
+
+Without arguments, `alias' prints the list of aliases in the reusable
+form `alias NAME=VALUE' on standard output.
+
Otherwise, an alias is defined for each NAME whose VALUE is given.
A trailing space in VALUE causes the next word to be checked for
-alias substitution when the alias is expanded. Alias returns
-true unless a NAME is given for which no alias has been defined.
+alias substitution when the alias is expanded.
+
+Options:
+ -p Print all defined aliases in a reusable format
+
+Exit Status:
+alias returns true unless a NAME is supplied for which no alias has been
+defined.
$END
#include <config.h>
@@ -103,7 +111,7 @@ alias_builtin (list)
free (alias_list); /* XXX - Do not free the strings. */
if (list == 0)
- return (EXECUTION_SUCCESS);
+ return (sh_chkwrite (EXECUTION_SUCCESS));
}
any_failed = 0;
@@ -149,8 +157,12 @@ $BUILTIN unalias
$FUNCTION unalias_builtin
$DEPENDS_ON ALIAS
$SHORT_DOC unalias [-a] name [name ...]
-Remove NAMEs from the list of defined aliases. If the -a option is given,
-then remove all alias definitions.
+Remove each NAME from the list of defined aliases.
+
+Options:
+ -a remove all alias definitions.
+
+Return success unless a NAME is not an existing alias.
$END
#if defined (ALIAS)
diff --git a/builtins/bashgetopt.c b/builtins/bashgetopt.c
index 4c8d907..b1b7070 100644
--- a/builtins/bashgetopt.c
+++ b/builtins/bashgetopt.c
@@ -2,21 +2,21 @@
/* Copyright (C) 1992-2002 Free Software Foundation, Inc.
-This file is part of GNU Bash, the Bourne Again SHell.
+ 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 2, or (at your option) any later
-version.
+ 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.
+ 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; see the file COPYING. If not, write to the Free Software
-Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
+ 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>
diff --git a/builtins/bashgetopt.h b/builtins/bashgetopt.h
index 835797c..f2aea26 100644
--- a/builtins/bashgetopt.h
+++ b/builtins/bashgetopt.h
@@ -4,19 +4,19 @@
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 2, 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; see the file COPYING. If not, write to the Free Software
- Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
+ 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/>.
+*/
/* See getopt.h for the explanation of these variables. */
diff --git a/builtins/bind.def b/builtins/bind.def
index 4711031..d0c953b 100644
--- a/builtins/bind.def
+++ b/builtins/bind.def
@@ -1,23 +1,22 @@
This file is bind.def, from which is created bind.c.
It implements the builtin "bind" in Bash.
-Copyright (C) 1987-2003 Free Software Foundation, Inc.
+Copyright (C) 1987-2009 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 2, or (at your option) any later
-version.
+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.
+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; see the file COPYING. If not, write to the Free Software
-Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
+You should have received a copy of the GNU General Public License
+along with Bash. If not, see <http://www.gnu.org/licenses/>.
$PRODUCES bind.c
@@ -27,12 +26,15 @@ $BUILTIN bind
$DEPENDS_ON READLINE
$FUNCTION bind_builtin
$SHORT_DOC bind [-lpvsPVS] [-m keymap] [-f filename] [-q name] [-u name] [-r keyseq] [-x keyseq:shell-command] [keyseq:readline-function or readline-command]
-Bind a key sequence to a Readline function or a macro, or set
-a Readline variable. The non-option argument syntax is equivalent
-to that found in ~/.inputrc, but must be passed as a single argument:
-bind '"\C-x\C-r": re-read-init-file'.
-bind accepts the following options:
- -m keymap Use `keymap' as the keymap for the duration of this
+Set Readline key bindings and variables.
+
+Bind a key sequence to a Readline function or a macro, or set a
+Readline variable. The non-option argument syntax is equivalent to
+that found in ~/.inputrc, but must be passed as a single argument:
+e.g., bind '"\C-x\C-r": re-read-init-file'.
+
+Options:
+ -m keymap Use KEYMAP as the keymap for the duration of this
command. Acceptable keymap names are emacs,
emacs-standard, emacs-meta, emacs-ctlx, vi, vi-move,
vi-command, and vi-insert.
@@ -40,18 +42,21 @@ bind accepts the following options:
-P List function names and bindings.
-p List functions and bindings in a form that can be
reused as input.
- -r keyseq Remove the binding for KEYSEQ.
- -x keyseq:shell-command Cause SHELL-COMMAND to be executed when
- KEYSEQ is entered.
- -f filename Read key bindings from FILENAME.
- -q function-name Query about which keys invoke the named function.
- -u function-name Unbind all keys which are bound to the named function.
- -V List variable names and values
- -v List variable names and values in a form that can
- be reused as input.
-S List key sequences that invoke macros and their values
-s List key sequences that invoke macros and their values
in a form that can be reused as input.
+ -V List variable names and values
+ -v List variable names and values in a form that can
+ be reused as input.
+ -q function-name Query about which keys invoke the named function.
+ -u function-name Unbind all keys which are bound to the named function.
+ -r keyseq Remove the binding for KEYSEQ.
+ -f filename Read key bindings from FILENAME.
+ -x keyseq:shell-command Cause SHELL-COMMAND to be executed when
+ KEYSEQ is entered.
+
+Exit Status:
+bind returns 0 unless an unrecognized option is given or an error occurs.
$END
#if defined (READLINE)
@@ -110,14 +115,21 @@ bind_builtin (list)
char *initfile, *map_name, *fun_name, *unbind_name, *remove_seq, *cmd_seq;
if (no_line_editing)
- return (EXECUTION_FAILURE);
+ {
+#if 0
+ builtin_error (_("line editing not enabled"));
+ return (EXECUTION_FAILURE);
+#else
+ builtin_warning (_("line editing not enabled"));
+#endif
+ }
kmap = saved_keymap = (Keymap) NULL;
flags = 0;
initfile = map_name = fun_name = unbind_name = remove_seq = (char *)NULL;
return_code = EXECUTION_SUCCESS;
- if (!bash_readline_initialized)
+ if (bash_readline_initialized == 0)
initialize_readline ();
begin_unwind_frame ("bind_builtin");
@@ -243,7 +255,7 @@ bind_builtin (list)
if ((flags & RFLAG) && remove_seq)
{
- if (rl_set_key (remove_seq, (rl_command_func_t *)NULL, rl_get_keymap ()) != 0)
+ if (rl_bind_keyseq (remove_seq, (rl_command_func_t *)NULL) != 0)
{
builtin_error (_("`%s': cannot unbind"), remove_seq);
BIND_RETURN (EXECUTION_FAILURE);
@@ -266,7 +278,7 @@ bind_builtin (list)
run_unwind_frame ("bind_builtin");
- return (return_code);
+ return (sh_chkwrite (return_code));
}
static int
@@ -310,7 +322,7 @@ unbind_command (name)
function = rl_named_function (name);
if (function == 0)
{
- builtin_error ("`%s': unknown function name", name);
+ builtin_error (_("`%s': unknown function name"), name);
return EXECUTION_FAILURE;
}
diff --git a/builtins/break.def b/builtins/break.def
index e61d502..232ac1a 100644
--- a/builtins/break.def
+++ b/builtins/break.def
@@ -1,31 +1,35 @@
This file is break.def, from which is created break.c.
It implements the builtins "break" and "continue" in Bash.
-Copyright (C) 1987-2003 Free Software Foundation, Inc.
+Copyright (C) 1987-2009 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 2, or (at your option) any later
-version.
+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.
+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; see the file COPYING. If not, write to the Free Software
-Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
+You should have received a copy of the GNU General Public License
+along with Bash. If not, see <http://www.gnu.org/licenses/>.
$PRODUCES break.c
$BUILTIN break
$FUNCTION break_builtin
$SHORT_DOC break [n]
-Exit from within a FOR, WHILE or UNTIL loop. If N is specified,
-break N levels.
+Exit for, while, or until loops.
+
+Exit a FOR, WHILE or UNTIL loop. If N is specified, break N enclosing
+loops.
+
+Exit Status:
+The exit status is 0 unless N is not greater than or equal to 1.
$END
#include <config.h>
@@ -66,11 +70,11 @@ break_builtin (list)
if (check_loop_level () == 0)
return (EXECUTION_SUCCESS);
- newbreak = get_numeric_arg (list, 1);
+ (void)get_numeric_arg (list, 1, &newbreak);
if (newbreak <= 0)
{
- sh_erange (list->word->word, "loop count");
+ sh_erange (list->word->word, _("loop count"));
breaking = loop_level;
return (EXECUTION_FAILURE);
}
@@ -86,8 +90,13 @@ break_builtin (list)
$BUILTIN continue
$FUNCTION continue_builtin
$SHORT_DOC continue [n]
-Resume the next iteration of the enclosing FOR, WHILE or UNTIL loop.
-If N is specified, resume at the N-th enclosing loop.
+Resume for, while, or until loops.
+
+Resumes the next iteration of the enclosing FOR, WHILE or UNTIL loop.
+If N is specified, resumes the Nth enclosing loop.
+
+Exit Status:
+The exit status is 0 unless N is not greater than or equal to 1.
$END
/* Set up to continue x levels, where x defaults to 1, but can be specified
@@ -101,11 +110,11 @@ continue_builtin (list)
if (check_loop_level () == 0)
return (EXECUTION_SUCCESS);
- newcont = get_numeric_arg (list, 1);
+ (void)get_numeric_arg (list, 1, &newcont);
if (newcont <= 0)
{
- sh_erange (list->word->word, "loop count");
+ sh_erange (list->word->word, _("loop count"));
breaking = loop_level;
return (EXECUTION_FAILURE);
}
diff --git a/builtins/builtin.def b/builtins/builtin.def
index dfa58bc..3e765e4 100644
--- a/builtins/builtin.def
+++ b/builtins/builtin.def
@@ -1,32 +1,37 @@
This file is builtin.def, from which is created builtin.c.
It implements the builtin "builtin" in Bash.
-Copyright (C) 1987-2002 Free Software Foundation, Inc.
+Copyright (C) 1987-2009 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 2, or (at your option) any later
-version.
+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.
+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; see the file COPYING. If not, write to the Free Software
-Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
+You should have received a copy of the GNU General Public License
+along with Bash. If not, see <http://www.gnu.org/licenses/>.
$PRODUCES builtin.c
$BUILTIN builtin
$FUNCTION builtin_builtin
$SHORT_DOC builtin [shell-builtin [arg ...]]
-Run a shell builtin. This is useful when you wish to rename a
-shell builtin to be a function, but need the functionality of the
-builtin within the function itself.
+Execute shell builtins.
+
+Execute SHELL-BUILTIN with arguments ARGs without performing command
+lookup. This is useful when you wish to reimplement a shell builtin
+as a shell function, but need to execute the builtin within the function.
+
+Exit Status:
+Returns the exit status of SHELL-BUILTIN, or false if SHELL-BUILTIN is
+not a shell builtin..
$END
#include <config.h>
diff --git a/builtins/caller.def b/builtins/caller.def
index f5f2c08..7ddbdad 100644
--- a/builtins/caller.def
+++ b/builtins/caller.def
@@ -1,39 +1,41 @@
This file is caller.def, from which is created caller.c. It implements the
builtin "caller" in Bash.
-Copyright (C) 2002-2003 Rocky Bernstein for Free Software Foundation, Inc.
+Copyright (C) 2002-2008 Rocky Bernstein for 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 2, or (at your option) any later
-version.
+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.
+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; see the file COPYING. If not, write to the Free Software
-Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
+You should have received a copy of the GNU General Public License
+along with Bash. If not, see <http://www.gnu.org/licenses/>.
$PRODUCES caller.c
$BUILTIN caller
$FUNCTION caller_builtin
$DEPENDS_ON DEBUGGER
-$SHORT_DOC caller [EXPR]
+$SHORT_DOC caller [expr]
+Return the context of the current subroutine call.
-Returns the context of the current subroutine call.
-
-Without EXPR, returns "$line $filename". With EXPR,
-returns "$line $subroutine $filename"; this extra information
-can be used to provide a stack trace.
+Without EXPR, returns "$line $filename". With EXPR, returns
+"$line $subroutine $filename"; this extra information can be used to
+provide a stack trace.
The value of EXPR indicates how many call frames to go back before the
current one; the top frame is frame 0.
+
+Exit Status:
+Returns 0 unless the shell is not executing a shell function or EXPR
+is invalid.
$END
#include <config.h>
@@ -128,14 +130,14 @@ caller_builtin (list)
#ifdef LOADABLE_BUILTIN
static char *caller_doc[] = {
- N_("Returns the context of the current subroutine call."),
- N_(" "),
- N_("Without EXPR, returns returns \"$line $filename\". With EXPR,"),
- N_("returns \"$line $subroutine $filename\"; this extra information"),
- N_("can be used used to provide a stack trace."),
- N_(" "),
- N_("The value of EXPR indicates how many call frames to go back before the"),
- N_("current one; the top frame is frame 0."),
+N_("Returns the context of the current subroutine call.\n\
+ \n\
+ Without EXPR, returns "$line $filename". With EXPR, returns\n\
+ "$line $subroutine $filename"; this extra information can be used to\n\
+ provide a stack trace.\n\
+ \n\
+ The value of EXPR indicates how many call frames to go back before the\n\
+ current one; the top frame is frame 0."),
(char *)NULL
};
diff --git a/builtins/cd.def b/builtins/cd.def
index 54e328e..d53b258 100644
--- a/builtins/cd.def
+++ b/builtins/cd.def
@@ -1,23 +1,22 @@
This file is cd.def, from which is created cd.c. It implements the
builtins "cd" and "pwd" in Bash.
-Copyright (C) 1987-2005 Free Software Foundation, Inc.
+Copyright (C) 1987-2009 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 2, or (at your option) any later
-version.
+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.
+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; see the file COPYING. If not, write to the Free Software
-Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
+You should have received a copy of the GNU General Public License
+along with Bash. If not, see <http://www.gnu.org/licenses/>.
$PRODUCES cd.c
#include <config.h>
@@ -56,15 +55,13 @@ extern int errno;
extern int posixly_correct;
extern int array_needs_making;
-extern char *bash_getcwd_errstr;
+extern const char * const bash_getcwd_errstr;
static int bindpwd __P((int));
static void setpwd __P((char *));
static char *resetpwd __P((char *));
static int change_to_directory __P((char *, int));
-static char *cdspell __P((char *));
-
/* Change this to 1 to get cd spelling correction by default. */
int cdspelling = 0;
@@ -73,17 +70,29 @@ int cdable_vars;
$BUILTIN cd
$FUNCTION cd_builtin
$SHORT_DOC cd [-L|-P] [dir]
-Change the current directory to DIR. The variable $HOME is the
-default DIR. The variable CDPATH defines the search path for
-the directory containing DIR. Alternative directory names in CDPATH
-are separated by a colon (:). A null directory name is the same as
-the current directory, i.e. `.'. If DIR begins with a slash (/),
-then CDPATH is not used. If the directory is not found, and the
-shell option `cdable_vars' is set, then try the word as a variable
-name. If that variable has a value, then cd to the value of that
-variable. The -P option says to use the physical directory structure
-instead of following symbolic links; the -L option forces symbolic links
-to be followed.
+Change the shell working directory.
+
+Change the current directory to DIR. The default DIR is the value of the
+HOME shell variable.
+
+The variable CDPATH defines the search path for the directory containing
+DIR. Alternative directory names in CDPATH are separated by a colon (:).
+A null directory name is the same as the current directory. If DIR begins
+with a slash (/), then CDPATH is not used.
+
+If the directory is not found, and the shell option `cdable_vars' is set,
+the word is assumed to be a variable name. If that variable has a value,
+its value is used for DIR.
+
+Options:
+ -L force symbolic links to be followed
+ -P use the physical directory structure without following symbolic
+ links
+
+The default is to follow symbolic links, as if `-L' were specified.
+
+Exit Status:
+Returns 0 if the directory is changed; non-zero otherwise.
$END
/* Just set $PWD, don't change OLDPWD. Used by `pwd -P' in posix mode. */
@@ -108,9 +117,11 @@ bindpwd (no_symlinks)
int no_symlinks;
{
char *dirname, *pwdvar;
- int old_anm;
+ int old_anm, r;
SHELL_VAR *tvar;
+ r = sh_chkwrite (EXECUTION_SUCCESS);
+
#define tcwd the_current_working_directory
dirname = tcwd ? (no_symlinks ? sh_physpath (tcwd, 0) : tcwd)
: get_working_directory ("cd");
@@ -131,7 +142,7 @@ bindpwd (no_symlinks)
if (dirname && dirname != the_current_working_directory)
free (dirname);
- return (EXECUTION_SUCCESS);
+ return (r);
}
/* Call get_working_directory to reset the value of
@@ -224,7 +235,7 @@ cd_builtin (list)
}
else if (absolute_pathname (list->word->word))
dirname = list->word->word;
- else if (cdpath = get_string_value ("CDPATH"))
+ else if (privileged_mode == 0 && (cdpath = get_string_value ("CDPATH")))
{
dirname = list->word->word;
@@ -300,7 +311,7 @@ cd_builtin (list)
typo. This is similar to the UNIX 8th and 9th Edition shells. */
if (lflag & LCD_DOSPELL)
{
- temp = cdspell (dirname);
+ temp = dirspell (dirname);
if (temp && change_to_directory (temp, no_symlinks))
{
printf ("%s\n", temp);
@@ -317,9 +328,18 @@ cd_builtin (list)
$BUILTIN pwd
$FUNCTION pwd_builtin
$SHORT_DOC pwd [-LP]
-Print the current working directory. With the -P option, pwd prints
-the physical directory, without any symbolic links; the -L option
-makes pwd follow symbolic links.
+Print the name of the current working directory.
+
+Options:
+ -L print the value of $PWD if it names the current working
+ directory
+ -P print the physical directory, without any symbolic links
+
+By default, `pwd' behaves as if `-L' were specified.
+
+Exit Status:
+Returns 0 unless an invalid option is given or the current directory
+cannot be read.
$END
/* Non-zero means that pwd always prints the physical directory, without
@@ -375,15 +395,7 @@ pwd_builtin (list)
setpwd (directory);
if (directory != the_current_working_directory)
free (directory);
- fflush (stdout);
- if (ferror (stdout))
- {
- sh_wrerror ();
- clearerr (stdout);
- return (EXECUTION_FAILURE);
- }
-
- return (EXECUTION_SUCCESS);
+ return (sh_chkwrite (EXECUTION_SUCCESS));
}
else
return (EXECUTION_FAILURE);
@@ -499,28 +511,3 @@ change_to_directory (newdir, nolinks)
free (tdir);
return r;
}
-
-/* Code for cd spelling correction. Original patch submitted by
- Neil Russel (caret@c-side.com). */
-
-static char *
-cdspell (dirname)
- char *dirname;
-{
- int n;
- char *guess;
-
- n = (strlen (dirname) * 3 + 1) / 2 + 1;
- guess = (char *)xmalloc (n);
-
- switch (spname (dirname, guess))
- {
- case -1:
- default:
- free (guess);
- return (char *)NULL;
- case 0:
- case 1:
- return guess;
- }
-}
diff --git a/builtins/colon.def b/builtins/colon.def
index a7cdc12..4b78b30 100644
--- a/builtins/colon.def
+++ b/builtins/colon.def
@@ -1,23 +1,22 @@
This file is colon.def, from which is created colon.c.
It implements the builtin ":" in Bash.
-Copyright (C) 1987-2002 Free Software Foundation, Inc.
+Copyright (C) 1987-2009 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 2, or (at your option) any later
-version.
+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.
+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; see the file COPYING. If not, write to the Free Software
-Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
+You should have received a copy of the GNU General Public License
+along with Bash. If not, see <http://www.gnu.org/licenses/>.
$PRODUCES colon.c
@@ -25,19 +24,30 @@ $BUILTIN :
$DOCNAME colon
$FUNCTION colon_builtin
$SHORT_DOC :
-No effect; the command does nothing. A zero exit code is returned.
+Null command.
+
+No effect; the command does nothing.
+
+Exit Status:
+Always succeeds.
$END
$BUILTIN true
$FUNCTION colon_builtin
$SHORT_DOC true
Return a successful result.
+
+Exit Status:
+Always succeeds.
$END
$BUILTIN false
$FUNCTION false_builtin
$SHORT_DOC false
Return an unsuccessful result.
+
+Exit Status:
+Always fails.
$END
/* Return a successful result. */
diff --git a/builtins/command.def b/builtins/command.def
index dbc1e9a..1845279 100644
--- a/builtins/command.def
+++ b/builtins/command.def
@@ -1,35 +1,42 @@
This file is command.def, from which is created command.c.
It implements the builtin "command" in Bash.
-Copyright (C) 1987-2004 Free Software Foundation, Inc.
+Copyright (C) 1987-2009 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 2, or (at your option) any later
-version.
+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.
+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; see the file COPYING. If not, write to the Free Software
-Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
+You should have received a copy of the GNU General Public License
+along with Bash. If not, see <http://www.gnu.org/licenses/>.
$PRODUCES command.c
$BUILTIN command
$FUNCTION command_builtin
$SHORT_DOC command [-pVv] command [arg ...]
-Runs COMMAND with ARGS ignoring shell functions. If you have a shell
-function called `ls', and you wish to call the command `ls', you can
-say "command ls". If the -p option is given, a default value is used
-for PATH that is guaranteed to find all of the standard utilities. If
-the -V or -v option is given, a string is printed describing COMMAND.
-The -V option produces a more verbose description.
+Execute a simple command or display information about commands.
+
+Runs COMMAND with ARGS suppressing shell function lookup, or display
+information about the specified COMMANDs. Can be used to invoke commands
+on disk when a function with the same name exists.
+
+Options:
+ -p use a default value for PATH that is guaranteed to find all of
+ the standard utilities
+ -v print a description of COMMAND similar to the `type' builtin
+ -V print a more verbose description of each COMMAND
+
+Exit Status:
+Returns exit status of COMMAND, or failure if COMMAND is not found.
$END
#include <config.h>
@@ -93,22 +100,6 @@ command_builtin (list)
if (list == 0)
return (EXECUTION_SUCCESS);
- if (verbose)
- {
- int found, any_found;
-
- for (any_found = 0; list; list = list->next)
- {
- found = describe_command (list->word->word, verbose);
-
- if (found == 0 && verbose != CDESC_REUSABLE)
- sh_notfound (list->word->word);
-
- any_found += found;
- }
- return (any_found ? EXECUTION_SUCCESS : EXECUTION_FAILURE);
- }
-
#if defined (RESTRICTED_SHELL)
if (use_standard_path && restricted)
{
@@ -119,8 +110,6 @@ command_builtin (list)
begin_unwind_frame ("command_builtin");
- /* We don't want this to be reparsed (consider command echo 'foo &'), so
- just make a simple_command structure and call execute_command with it. */
if (use_standard_path)
{
old_path = get_string_value ("PATH");
@@ -132,11 +121,32 @@ command_builtin (list)
standard_path = get_standard_path ();
bind_variable ("PATH", standard_path ? standard_path : "", 0);
+ stupidly_hack_special_variables ("PATH");
FREE (standard_path);
}
+ if (verbose)
+ {
+ int found, any_found;
+
+ for (any_found = 0; list; list = list->next)
+ {
+ found = describe_command (list->word->word, verbose);
+
+ if (found == 0 && verbose != CDESC_REUSABLE)
+ sh_notfound (list->word->word);
+
+ any_found += found;
+ }
+
+ run_unwind_frame ("command_builtin");
+ return (any_found ? EXECUTION_SUCCESS : EXECUTION_FAILURE);
+ }
+
#define COMMAND_BUILTIN_FLAGS (CMD_NO_FUNCTIONS | CMD_INHIBIT_EXPANSION | CMD_COMMAND_BUILTIN)
+ /* We don't want this to be reparsed (consider command echo 'foo &'), so
+ just make a simple_command structure and call execute_command with it. */
command = make_bare_simple_command ();
command->value.Simple->words = (WORD_LIST *)copy_word_list (list);
command->value.Simple->redirects = (REDIRECT *)NULL;
@@ -175,6 +185,8 @@ restore_path (var)
}
else
unbind_variable ("PATH");
+
+ stupidly_hack_special_variables ("PATH");
}
/* Return a value for PATH that is guaranteed to find all of the standard
diff --git a/builtins/common.c b/builtins/common.c
index 7b9613e..f02e99c 100644
--- a/builtins/common.c
+++ b/builtins/common.c
@@ -1,20 +1,22 @@
-/* Copyright (C) 1987-2005 Free Software Foundation, Inc.
+/* common.c - utility functions for all builtins */
+
+/* Copyright (C) 1987-2009 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 2, or (at your option) any later
- version.
+ 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.
- 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; see the file COPYING. If not, write to the Free Software
- Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
+ 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>
@@ -42,6 +44,8 @@
#include "../bashansi.h"
#include "../bashintl.h"
+#define NEED_FPURGE_DECL
+
#include "../shell.h"
#include "maxpath.h"
#include "../flags.h"
@@ -69,7 +73,7 @@ extern int last_command_exit_value;
extern int running_trap;
extern int posixly_correct;
extern char *this_command_name, *shell_name;
-extern char *bash_getcwd_errstr;
+extern const char * const bash_getcwd_errstr;
/* Used by some builtins and the mainline code. */
sh_builtin_func_t *last_shell_builtin = (sh_builtin_func_t *)NULL;
@@ -84,6 +88,22 @@ sh_builtin_func_t *this_shell_builtin = (sh_builtin_func_t *)NULL;
/* This is a lot like report_error (), but it is for shell builtins
instead of shell control structures, and it won't ever exit the
shell. */
+
+static void
+builtin_error_prolog ()
+{
+ char *name;
+
+ name = get_name_for_error ();
+ fprintf (stderr, "%s: ", name);
+
+ if (interactive_shell == 0)
+ fprintf (stderr, _("line %d: "), executing_line_number ());
+
+ if (this_command_name && *this_command_name)
+ fprintf (stderr, "%s: ", this_command_name);
+}
+
void
#if defined (PREFER_STDARG)
builtin_error (const char *format, ...)
@@ -94,16 +114,29 @@ builtin_error (format, va_alist)
#endif
{
va_list args;
- char *name;
- name = get_name_for_error ();
- fprintf (stderr, "%s: ", name);
+ builtin_error_prolog ();
- if (interactive_shell == 0)
- fprintf (stderr, "line %d: ", executing_line_number ());
+ SH_VA_START (args, format);
- if (this_command_name && *this_command_name)
- fprintf (stderr, "%s: ", this_command_name);
+ vfprintf (stderr, format, args);
+ va_end (args);
+ fprintf (stderr, "\n");
+}
+
+void
+#if defined (PREFER_STDARG)
+builtin_warning (const char *format, ...)
+#else
+builtin_warning (format, va_alist)
+ const char *format;
+ va_dcl
+#endif
+{
+ va_list args;
+
+ builtin_error_prolog ();
+ fprintf (stderr, _("warning: "));
SH_VA_START (args, format);
@@ -117,7 +150,7 @@ void
builtin_usage ()
{
if (this_command_name && *this_command_name)
- fprintf (stderr, "%s: usage: ", this_command_name);
+ fprintf (stderr, _("%s: usage: "), this_command_name);
fprintf (stderr, "%s\n", current_builtin->short_doc);
fflush (stderr);
}
@@ -131,6 +164,7 @@ no_args (list)
if (list)
{
builtin_error (_("too many arguments"));
+ top_level_cleanup ();
jump_to_top_level (DISCARD);
}
}
@@ -198,7 +232,15 @@ void
sh_invalidnum (s)
char *s;
{
- builtin_error (_("%s: invalid number"), s);
+ char *msg;
+
+ if (*s == '0' && isdigit (s[1]))
+ msg = _("invalid octal number");
+ else if (*s == '0' && s[1] == 'x')
+ msg = _("invalid hex number");
+ else
+ msg = _("invalid number");
+ builtin_error ("%s: %s", s, msg);
}
void
@@ -273,9 +315,37 @@ sh_notbuiltin (s)
void
sh_wrerror ()
{
+#if defined (DONT_REPORT_BROKEN_PIPE_WRITE_ERRORS) && defined (EPIPE)
+ if (errno != EPIPE)
+#endif /* DONT_REPORT_BROKEN_PIPE_WRITE_ERRORS && EPIPE */
builtin_error (_("write error: %s"), strerror (errno));
}
+void
+sh_ttyerror (set)
+ int set;
+{
+ if (set)
+ builtin_error (_("error setting terminal attributes: %s"), strerror (errno));
+ else
+ builtin_error (_("error getting terminal attributes: %s"), strerror (errno));
+}
+
+int
+sh_chkwrite (s)
+ int s;
+{
+ fflush (stdout);
+ if (ferror (stdout))
+ {
+ sh_wrerror ();
+ fpurge (stdout);
+ clearerr (stdout);
+ return (EXECUTION_FAILURE);
+ }
+ return (s);
+}
+
/* **************************************************************** */
/* */
/* Shell positional parameter manipulation */
@@ -371,36 +441,44 @@ set_dollar_vars_changed ()
/* Read a numeric arg for this_command_name, the name of the shell builtin
that wants it. LIST is the word list that the arg is to come from.
Accept only the numeric argument; report an error if other arguments
- follow. If FATAL is true, call throw_to_top_level, which exits the
- shell; if not, call jump_to_top_level (DISCARD), which aborts the
- current command. */
-intmax_t
-get_numeric_arg (list, fatal)
+ follow. If FATAL is 1, call throw_to_top_level, which exits the
+ shell; if it's 2, call jump_to_top_level (DISCARD), which aborts the
+ current command; if FATAL is 0, return an indication of an invalid
+ number by setting *NUMOK == 0 and return -1. */
+int
+get_numeric_arg (list, fatal, count)
WORD_LIST *list;
int fatal;
+ intmax_t *count;
{
- intmax_t count = 1;
+ char *arg;
+
+ if (count)
+ *count = 1;
if (list && list->word && ISOPTION (list->word->word, '-'))
list = list->next;
if (list)
{
- register char *arg;
-
arg = list->word->word;
- if (arg == 0 || (legal_number (arg, &count) == 0))
+ if (arg == 0 || (legal_number (arg, count) == 0))
{
- sh_neednumarg (list->word->word);
- if (fatal)
+ sh_neednumarg (list->word->word ? list->word->word : "`'");
+ if (fatal == 0)
+ return 0;
+ else if (fatal == 1) /* fatal == 1; abort */
throw_to_top_level ();
- else
- jump_to_top_level (DISCARD);
+ else /* fatal == 2; discard current command */
+ {
+ top_level_cleanup ();
+ jump_to_top_level (DISCARD);
+ }
}
no_args (list->next);
}
- return (count);
+ return (1);
}
/* Get an eight-bit status value from LIST */
@@ -475,7 +553,11 @@ get_working_directory (for_whom)
if (the_current_working_directory == 0)
{
+#if defined (GETCWD_BROKEN)
+ the_current_working_directory = getcwd (0, PATH_MAX);
+#else
the_current_working_directory = getcwd (0, 0);
+#endif
if (the_current_working_directory == 0)
{
fprintf (stderr, _("%s: error retrieving current directory: %s: %s\n"),
@@ -530,7 +612,7 @@ get_job_by_name (name, flags)
match = STREQN (p->command, name, cl);
}
else if (flags & JM_SUBSTRING)
- match = strindex (p->command, name) != (char *)0;
+ match = strcasestr (p->command, name) != (char *)0;
else
match = STREQN (p->command, name, wl);
@@ -639,7 +721,7 @@ display_signal_list (list, forcecols)
{
printf ("%2d) %s", i, name);
- if (++column < 4)
+ if (++column < 5)
printf ("\t");
else
{
diff --git a/builtins/common.h b/builtins/common.h
index 1233d66..efbb078 100644
--- a/builtins/common.h
+++ b/builtins/common.h
@@ -4,19 +4,19 @@
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 2, or (at your option) any later
- version.
+ 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.
+ 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; see the file COPYING. If not, write to the Free Software
- Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
+ You should have received a copy of the GNU General Public License
+ along with Bash. If not, see <http://www.gnu.org/licenses/>.
+*/
#if !defined (__COMMON_H)
# define __COMMON_H
@@ -31,6 +31,8 @@
#define SEVAL_NOHIST 0x004
#define SEVAL_NOFREE 0x008
#define SEVAL_RESETLINE 0x010
+#define SEVAL_PARSEONLY 0x020
+#define SEVAL_NOLONGJMP 0x040
/* Flags for describe_command, shared between type.def and command.def */
#define CDESC_ALL 0x001 /* type -a */
@@ -57,6 +59,7 @@
/* Functions from common.c */
extern void builtin_error __P((const char *, ...)) __attribute__((__format__ (printf, 1, 2)));
+extern void builtin_warning __P((const char *, ...)) __attribute__((__format__ (printf, 1, 2)));
extern void builtin_usage __P((void));
extern void no_args __P((WORD_LIST *));
extern int no_options __P((WORD_LIST *));
@@ -78,6 +81,8 @@ extern void sh_nojobs __P((char *));
extern void sh_restricted __P((char *));
extern void sh_notbuiltin __P((char *));
extern void sh_wrerror __P((void));
+extern void sh_ttyerror __P((int));
+extern int sh_chkwrite __P((int));
extern char **make_builtin_argv __P((WORD_LIST *, int *));
extern void remember_args __P((WORD_LIST *, int));
@@ -86,7 +91,7 @@ extern int dollar_vars_changed __P((void));
extern void set_dollar_vars_unchanged __P((void));
extern void set_dollar_vars_changed __P((void));
-extern intmax_t get_numeric_arg __P((WORD_LIST *, int));
+extern int get_numeric_arg __P((WORD_LIST *, int, intmax_t *));
extern int get_exitstat __P((WORD_LIST *));
extern int read_octal __P((char *));
@@ -134,13 +139,18 @@ extern char **get_shopt_options __P((void));
extern int shopt_setopt __P((char *, int));
extern int shopt_listopt __P((char *, int));
-extern int set_login_shell __P((int));
+extern int set_login_shell __P((char *, int));
+
+extern void set_bashopts __P((void));
+extern void parse_bashopts __P((char *));
+extern void initialize_bashopts __P((int));
/* Functions from type.def */
extern int describe_command __P((char *, int));
/* Functions from setattr.def */
extern int set_or_show_attributes __P((WORD_LIST *, int, int));
+extern int show_all_var_attributes __P((int, int));
extern int show_var_attributes __P((SHELL_VAR *, int, int));
extern int show_name_attributes __P((char *, int));
extern void set_var_attribute __P((char *, int, int));
@@ -154,6 +164,7 @@ extern WORD_LIST *get_directory_stack __P((int));
/* Functions from evalstring.c */
extern int parse_and_execute __P((char *, const char *, int));
extern void parse_and_execute_cleanup __P((void));
+extern int parse_string __P((char *, const char *, int, char **));
/* Functions from evalfile.c */
extern int maybe_execute_file __P((const char *, int));
diff --git a/builtins/complete.def b/builtins/complete.def
index a859b88..2267794 100644
--- a/builtins/complete.def
+++ b/builtins/complete.def
@@ -1,35 +1,50 @@
This file is complete.def, from which is created complete.c.
-It implements the builtins "complete" and "compgen" in Bash.
+It implements the builtins "complete", "compgen", and "compopt" in Bash.
-Copyright (C) 1999-2003 Free Software Foundation, Inc.
+Copyright (C) 1999-2009 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 2, or (at your option) any later
-version.
+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.
+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; see the file COPYING. If not, write to the Free Software
-Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
+You should have received a copy of the GNU General Public License
+along with Bash. If not, see <http://www.gnu.org/licenses/>.
$PRODUCES complete.c
$BUILTIN complete
$DEPENDS_ON PROGRAMMABLE_COMPLETION
$FUNCTION complete_builtin
-$SHORT_DOC complete [-abcdefgjksuv] [-pr] [-o option] [-A action] [-G globpat] [-W wordlist] [-P prefix] [-S suffix] [-X filterpat] [-F function] [-C command] [name ...]
-For each NAME, specify how arguments are to be completed.
-If the -p option is supplied, or if no options are supplied, existing
-completion specifications are printed in a way that allows them to be
-reused as input. The -r option removes a completion specification for
-each NAME, or, if no NAMEs are supplied, all completion specifications.
+$SHORT_DOC complete [-abcdefgjksuv] [-pr] [-DE] [-o option] [-A action] [-G globpat] [-W wordlist] [-F function] [-C command] [-X filterpat] [-P prefix] [-S suffix] [name ...]
+Specify how arguments are to be completed by Readline.
+
+For each NAME, specify how arguments are to be completed. If no options
+are supplied, existing completion specifications are printed in a way that
+allows them to be reused as input.
+
+Options:
+ -p print existing completion specifications in a reusable format
+ -r remove a completion specification for each NAME, or, if no
+ NAMEs are supplied, all completion specifications
+ -D apply the completions and actions as the default for commands
+ without any specific completion defined
+ -E apply the completions and actions to "empty" commands --
+ completion attempted on a blank line
+
+When completion is attempted, the actions are applied in the order the
+uppercase-letter options are listed above. The -D option takes
+precedence over -E.
+
+Exit Status:
+Returns success unless an invalid option is supplied or an error occurs.
$END
#include <config.h>
@@ -57,22 +72,32 @@ $END
#define STRDUP(x) ((x) ? savestring (x) : (char *)NULL)
+/* Structure containing all the non-action (binary) options; filled in by
+ build_actions(). */
+struct _optflags {
+ int pflag;
+ int rflag;
+ int Dflag;
+ int Eflag;
+};
+
static int find_compact __P((char *));
static int find_compopt __P((char *));
-static int build_actions __P((WORD_LIST *, int *, int *, unsigned long *, unsigned long *));
+static int build_actions __P((WORD_LIST *, struct _optflags *, unsigned long *, unsigned long *));
static int remove_cmd_completions __P((WORD_LIST *));
static int print_one_completion __P((char *, COMPSPEC *));
static int print_compitem __P((BUCKET_CONTENTS *));
+static void print_compopts __P((const char *, COMPSPEC *, int));
static void print_all_completions __P((void));
static int print_cmd_completions __P((WORD_LIST *));
static char *Garg, *Warg, *Parg, *Sarg, *Xarg, *Farg, *Carg;
-static struct _compacts {
- char *actname;
+static const struct _compacts {
+ const char * const actname;
int actflag;
int actopt;
} compacts[] = {
@@ -104,8 +129,8 @@ static struct _compacts {
};
/* This should be a STRING_INT_ALIST */
-static struct _compopt {
- char *optname;
+const static struct _compopt {
+ const char * const optname;
int optflag;
} compopts[] = {
{ "bashdefault", COPT_BASHDEFAULT },
@@ -156,9 +181,9 @@ find_compopt (name)
*/
static int
-build_actions (list, pp, rp, actp, optp)
+build_actions (list, flagp, actp, optp)
WORD_LIST *list;
- int *pp, *rp;
+ struct _optflags *flagp;
unsigned long *actp, *optp;
{
int opt, ind, opt_given;
@@ -168,15 +193,15 @@ build_actions (list, pp, rp, actp, optp)
opt_given = 0;
reset_internal_getopt ();
- while ((opt = internal_getopt (list, "abcdefgjko:prsuvA:G:W:P:S:X:F:C:")) != -1)
+ while ((opt = internal_getopt (list, "abcdefgjko:prsuvA:G:W:P:S:X:F:C:DE")) != -1)
{
opt_given = 1;
switch (opt)
{
case 'r':
- if (rp)
+ if (flagp)
{
- *rp = 1;
+ flagp->rflag = 1;
break;
}
else
@@ -187,9 +212,9 @@ build_actions (list, pp, rp, actp, optp)
}
case 'p':
- if (pp)
+ if (flagp)
{
- *pp = 1;
+ flagp->pflag = 1;
break;
}
else
@@ -256,6 +281,30 @@ build_actions (list, pp, rp, actp, optp)
case 'C':
Carg = list_optarg;
break;
+ case 'D':
+ if (flagp)
+ {
+ flagp->Dflag = 1;
+ break;
+ }
+ else
+ {
+ sh_invalidopt ("-D");
+ builtin_usage ();
+ return (EX_USAGE);
+ }
+ case 'E':
+ if (flagp)
+ {
+ flagp->Eflag = 1;
+ break;
+ }
+ else
+ {
+ sh_invalidopt ("-E");
+ builtin_usage ();
+ return (EX_USAGE);
+ }
case 'F':
Farg = list_optarg;
break;
@@ -291,9 +340,11 @@ int
complete_builtin (list)
WORD_LIST *list;
{
- int opt_given, pflag, rflag, rval;
+ int opt_given, rval;
unsigned long acts, copts;
COMPSPEC *cs;
+ struct _optflags oflags;
+ WORD_LIST *l, *wl;
if (list == 0)
{
@@ -301,24 +352,34 @@ complete_builtin (list)
return (EXECUTION_SUCCESS);
}
- opt_given = pflag = rflag = 0;
+ opt_given = oflags.pflag = oflags.rflag = oflags.Dflag = oflags.Eflag = 0;
+
acts = copts = (unsigned long)0L;
Garg = Warg = Parg = Sarg = Xarg = Farg = Carg = (char *)NULL;
cs = (COMPSPEC *)NULL;
/* Build the actions from the arguments. Also sets the [A-Z]arg variables
as a side effect if they are supplied as options. */
- rval = build_actions (list, &pflag, &rflag, &acts, &copts);
+ rval = build_actions (list, &oflags, &acts, &copts);
if (rval == EX_USAGE)
return (rval);
opt_given = rval != EXECUTION_FAILURE;
list = loptend;
+ wl = oflags.Dflag ? make_word_list (make_bare_word (DEFAULTCMD), (WORD_LIST *)NULL)
+ : (oflags.Eflag ? make_word_list (make_bare_word (EMPTYCMD), (WORD_LIST *)NULL) : 0);
+
/* -p overrides everything else */
- if (pflag || (list == 0 && opt_given == 0))
+ if (oflags.pflag || (list == 0 && opt_given == 0))
{
- if (list == 0)
+ if (wl)
+ {
+ rval = print_cmd_completions (wl);
+ dispose_words (wl);
+ return rval;
+ }
+ else if (list == 0)
{
print_all_completions ();
return (EXECUTION_SUCCESS);
@@ -327,9 +388,15 @@ complete_builtin (list)
}
/* next, -r overrides everything else. */
- if (rflag)
+ if (oflags.rflag)
{
- if (list == 0)
+ if (wl)
+ {
+ rval = remove_cmd_completions (wl);
+ dispose_words (wl);
+ return rval;
+ }
+ else if (list == 0)
{
progcomp_flush ();
return (EXECUTION_SUCCESS);
@@ -337,7 +404,7 @@ complete_builtin (list)
return (remove_cmd_completions (list));
}
- if (list == 0 && opt_given)
+ if (wl == 0 && list == 0 && opt_given)
{
builtin_usage ();
return (EX_USAGE);
@@ -357,13 +424,14 @@ complete_builtin (list)
cs->command = STRDUP (Carg);
cs->filterpat = STRDUP (Xarg);
- for (rval = EXECUTION_SUCCESS ; list; list = list->next)
+ for (rval = EXECUTION_SUCCESS, l = wl ? wl : list ; l; l = l->next)
{
/* Add CS as the compspec for the specified commands. */
- if (progcomp_insert (list->word->word, cs) == 0)
+ if (progcomp_insert (l->word->word, cs) == 0)
rval = EXECUTION_FAILURE;
}
+ dispose_words (wl);
return (rval);
}
@@ -419,6 +487,14 @@ remove_cmd_completions (list)
printf ("-o %s ", f); \
} while (0)
+#define XPRINTCOMPOPT(a, f) \
+ do { \
+ if (copts & a) \
+ printf ("-o %s ", f); \
+ else \
+ printf ("+o %s ", f); \
+ } while (0)
+
static int
print_one_completion (cmd, cs)
char *cmd;
@@ -478,15 +554,59 @@ print_one_completion (cmd, cs)
SQPRINTARG (cs->suffix, "-S");
SQPRINTARG (cs->filterpat, "-X");
+ SQPRINTARG (cs->command, "-C");
+
/* simple arguments that don't require quoting */
PRINTARG (cs->funcname, "-F");
- PRINTARG (cs->command, "-C");
- printf ("%s\n", cmd);
+ if (STREQ (cmd, EMPTYCMD))
+ printf ("-E\n");
+ else if (STREQ (cmd, DEFAULTCMD))
+ printf ("-D\n");
+ else
+ printf ("%s\n", cmd);
return (0);
}
+static void
+print_compopts (cmd, cs, full)
+ const char *cmd;
+ COMPSPEC *cs;
+ int full;
+{
+ int copts;
+
+ printf ("compopt ");
+ copts = cs->options;
+
+ if (full)
+ {
+ XPRINTCOMPOPT (COPT_BASHDEFAULT, "bashdefault");
+ XPRINTCOMPOPT (COPT_DEFAULT, "default");
+ XPRINTCOMPOPT (COPT_DIRNAMES, "dirnames");
+ XPRINTCOMPOPT (COPT_FILENAMES, "filenames");
+ XPRINTCOMPOPT (COPT_NOSPACE, "nospace");
+ XPRINTCOMPOPT (COPT_PLUSDIRS, "plusdirs");
+ }
+ else
+ {
+ PRINTCOMPOPT (COPT_BASHDEFAULT, "bashdefault");
+ PRINTCOMPOPT (COPT_DEFAULT, "default");
+ PRINTCOMPOPT (COPT_DIRNAMES, "dirnames");
+ PRINTCOMPOPT (COPT_FILENAMES, "filenames");
+ PRINTCOMPOPT (COPT_NOSPACE, "nospace");
+ PRINTCOMPOPT (COPT_PLUSDIRS, "plusdirs");
+ }
+
+ if (STREQ (cmd, EMPTYCMD))
+ printf ("-E\n");
+ else if (STREQ (cmd, DEFAULTCMD))
+ printf ("-D\n");
+ else
+ printf ("%s\n", cmd);
+}
+
static int
print_compitem (item)
BUCKET_CONTENTS *item;
@@ -525,17 +645,22 @@ print_cmd_completions (list)
ret = EXECUTION_FAILURE;
}
}
- return (ret);
+
+ return (sh_chkwrite (ret));
}
$BUILTIN compgen
$DEPENDS_ON PROGRAMMABLE_COMPLETION
$FUNCTION compgen_builtin
-$SHORT_DOC compgen [-abcdefgjksuv] [-o option] [-A action] [-G globpat] [-W wordlist] [-P prefix] [-S suffix] [-X filterpat] [-F function] [-C command] [word]
-Display the possible completions depending on the options. Intended
-to be used from within a shell function generating possible completions.
-If the optional WORD argument is supplied, matches against WORD are
-generated.
+$SHORT_DOC compgen [-abcdefgjksuv] [-o option] [-A action] [-G globpat] [-W wordlist] [-F function] [-C command] [-X filterpat] [-P prefix] [-S suffix] [word]
+Display possible completions depending on the options.
+
+Intended to be used from within a shell function generating possible
+completions. If the optional WORD argument is supplied, matches against
+WORD are generated.
+
+Exit Status:
+Returns success unless an invalid option is supplied or an error occurs.
$END
int
@@ -557,7 +682,7 @@ compgen_builtin (list)
/* Build the actions from the arguments. Also sets the [A-Z]arg variables
as a side effect if they are supplied as options. */
- rval = build_actions (list, (int *)NULL, (int *)NULL, &acts, &copts);
+ rval = build_actions (list, (struct _optflags *)NULL, &acts, &copts);
if (rval == EX_USAGE)
return (rval);
if (rval == EXECUTION_FAILURE)
@@ -587,7 +712,7 @@ compgen_builtin (list)
cs->filterpat = STRDUP (Xarg);
rval = EXECUTION_FAILURE;
- sl = gen_compspec_completions (cs, "compgen", word, 0, 0);
+ sl = gen_compspec_completions (cs, "compgen", word, 0, 0, 0);
/* If the compspec wants the bash default completions, temporarily
turn off programmable completion and call the bash completion code. */
@@ -620,3 +745,125 @@ compgen_builtin (list)
compspec_dispose (cs);
return (rval);
}
+
+$BUILTIN compopt
+$DEPENDS_ON PROGRAMMABLE_COMPLETION
+$FUNCTION compopt_builtin
+$SHORT_DOC compopt [-o|+o option] [-DE] [name ...]
+Modify or display completion options.
+
+Modify the completion options for each NAME, or, if no NAMEs are supplied,
+the completion currently begin executed. If no OPTIONs are givenm, print
+the completion options for each NAME or the current completion specification.
+
+Options:
+ -o option Set completion option OPTION for each NAME
+ -D Change options for the "default" command completion
+ -E Change options for the "empty" command completion
+
+Using `+o' instead of `-o' turns off the specified option.
+
+Arguments:
+
+Each NAME refers to a command for which a completion specification must
+have previously been defined using the `complete' builtin. If no NAMEs
+are supplied, compopt must be called by a function currently generating
+completions, and the options for that currently-executing completion
+generator are modified.
+
+Exit Status:
+Returns success unless an invalid option is supplied or NAME does not
+have a completion specification defined.
+$END
+
+int
+compopt_builtin (list)
+ WORD_LIST *list;
+{
+ int opts_on, opts_off, *opts, opt, oind, ret, Dflag, Eflag;
+ WORD_LIST *l, *wl;
+ COMPSPEC *cs;
+
+ opts_on = opts_off = Eflag = Dflag = 0;
+ ret = EXECUTION_SUCCESS;
+
+ reset_internal_getopt ();
+ while ((opt = internal_getopt (list, "+o:DE")) != EOF)
+ {
+ opts = (list_opttype == '-') ? &opts_on : &opts_off;
+
+ switch (opt)
+ {
+ case 'o':
+ oind = find_compopt (list_optarg);
+ if (oind < 0)
+ {
+ sh_invalidoptname (list_optarg);
+ return (EX_USAGE);
+ }
+ *opts |= compopts[oind].optflag;
+ break;
+ case 'D':
+ Dflag = 1;
+ break;
+ case 'E':
+ Eflag = 1;
+ break;
+ default:
+ builtin_usage ();
+ return (EX_USAGE);
+ }
+ }
+ list = loptend;
+
+ wl = Dflag ? make_word_list (make_bare_word (DEFAULTCMD), (WORD_LIST *)NULL)
+ : (Eflag ? make_word_list (make_bare_word (EMPTYCMD), (WORD_LIST *)NULL) : 0);
+
+ if (list == 0 && wl == 0)
+ {
+ if (RL_ISSTATE (RL_STATE_COMPLETING) == 0 || pcomp_curcs == 0)
+ {
+ builtin_error (_("not currently executing completion function"));
+ return (EXECUTION_FAILURE);
+ }
+ cs = pcomp_curcs;
+
+ if (opts_on == 0 && opts_off == 0)
+ {
+ print_compopts (pcomp_curcmd, cs, 1);
+ return (sh_chkwrite (ret));
+ }
+
+ /* Set the compspec options */
+ pcomp_set_compspec_options (cs, opts_on, 1);
+ pcomp_set_compspec_options (cs, opts_off, 0);
+
+ /* And change the readline variables the options control */
+ pcomp_set_readline_variables (opts_on, 1);
+ pcomp_set_readline_variables (opts_off, 0);
+
+ return (ret);
+ }
+
+ for (l = wl ? wl : list; l; l = l->next)
+ {
+ cs = progcomp_search (l->word->word);
+ if (cs == 0)
+ {
+ builtin_error (_("%s: no completion specification"), l->word->word);
+ ret = EXECUTION_FAILURE;
+ continue;
+ }
+ if (opts_on == 0 && opts_off == 0)
+ {
+ print_compopts (l->word->word, cs, 1);
+ continue; /* XXX -- fill in later */
+ }
+
+ /* Set the compspec options */
+ pcomp_set_compspec_options (cs, opts_on, 1);
+ pcomp_set_compspec_options (cs, opts_off, 0);
+ }
+
+ return (ret);
+}
diff --git a/builtins/declare.def b/builtins/declare.def
index 4d94fac..a0ce605 100644
--- a/builtins/declare.def
+++ b/builtins/declare.def
@@ -1,59 +1,67 @@
This file is declare.def, from which is created declare.c.
It implements the builtins "declare" and "local" in Bash.
-Copyright (C) 1987-2004 Free Software Foundation, Inc.
+Copyright (C) 1987-2009 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 2, or (at your option) any later
-version.
+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.
+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; see the file COPYING. If not, write to the Free Software
-Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
+You should have received a copy of the GNU General Public License
+along with Bash. If not, see <http://www.gnu.org/licenses/>.
$PRODUCES declare.c
$BUILTIN declare
$FUNCTION declare_builtin
-$SHORT_DOC declare [-afFirtx] [-p] [name[=value] ...]
-Declare variables and/or give them attributes. If no NAMEs are
-given, then display the values of variables instead. The -p option
-will display the attributes and values of each NAME.
+$SHORT_DOC declare [-aAfFilrtux] [-p] [name[=value] ...]
+Set variable values and attributes.
-The flags are:
+Declare variables and give them attributes. If no NAMEs are given,
+display the attributes and values of all variables.
- -a to make NAMEs arrays (if supported)
- -f to select from among function names only
- -F to display function names (and line number and source file name if
- debugging) without definitions
+Options:
+ -f restrict action or display to function names and definitions
+ -F restrict display to function names only (plus line number and
+ source file when debugging)
+ -p display the attributes and value of each NAME
+
+Options which set attributes:
+ -a to make NAMEs indexed arrays (if supported)
+ -A to make NAMEs associative arrays (if supported)
-i to make NAMEs have the `integer' attribute
+ -l to convert NAMEs to lower case on assignment
-r to make NAMEs readonly
-t to make NAMEs have the `trace' attribute
+ -u to convert NAMEs to upper case on assignment
-x to make NAMEs export
+Using `+' instead of `-' turns off the given attribute.
+
Variables with the integer attribute have arithmetic evaluation (see
-`let') done when the variable is assigned to.
+the `let' command) performed when the variable is assigned a value.
-When displaying values of variables, -f displays a function's name
-and definition. The -F option restricts the display to function
-name only.
+When used in a function, `declare' makes NAMEs local, as with the `local'
+command.
-Using `+' instead of `-' turns off the given attribute instead. When
-used in a function, makes NAMEs local, as with the `local' command.
+Exit Status:
+Returns success unless an invalid option is supplied or an error occurs.
$END
$BUILTIN typeset
$FUNCTION declare_builtin
-$SHORT_DOC typeset [-afFirtx] [-p] name[=value] ...
-Obsolete. See `declare'.
+$SHORT_DOC typeset [-aAfFilrtux] [-p] name[=value] ...
+Set variable values and attributes.
+
+Obsolete. See `help declare'.
$END
#include <config.h>
@@ -90,10 +98,18 @@ declare_builtin (list)
$BUILTIN local
$FUNCTION local_builtin
-$SHORT_DOC local name[=value] ...
-Create a local variable called NAME, and give it VALUE. LOCAL
-can only be used within a function; it makes the variable NAME
-have a visible scope restricted to that function and its children.
+$SHORT_DOC local [option] name[=value] ...
+Define local variables.
+
+Create a local variable called NAME, and give it VALUE. OPTION can
+be any option accepted by `declare'.
+
+Local variables can only be used within a function; they are visible
+only to the function where they are defined and its children.
+
+Exit Status:
+Returns success unless an invalid option is supplied, an error occurs,
+or the shell is not executing a function.
$END
int
local_builtin (list)
@@ -109,9 +125,9 @@ local_builtin (list)
}
#if defined (ARRAY_VARS)
-# define DECLARE_OPTS "+afiprtxF"
+# define DECLARE_OPTS "+acfilprtuxAF"
#else
-# define DECLARE_OPTS "+fiprtxF"
+# define DECLARE_OPTS "+cfilprtuxF"
#endif
/* The workhorse function. */
@@ -120,7 +136,8 @@ declare_internal (list, local_var)
register WORD_LIST *list;
int local_var;
{
- int flags_on, flags_off, *flags, any_failed, assign_error, pflag, nodefs, opt;
+ int flags_on, flags_off, *flags;
+ int any_failed, assign_error, pflag, nodefs, opt;
char *t, *subscript_start;
SHELL_VAR *var;
FUNCTION_DEF *shell_fn;
@@ -136,8 +153,19 @@ declare_internal (list, local_var)
case 'a':
#if defined (ARRAY_VARS)
*flags |= att_array;
+ break;
+#else
+ builtin_usage ();
+ return (EX_USAGE);
#endif
+ case 'A':
+#if defined (ARRAY_VARS)
+ *flags |= att_assoc;
break;
+#else
+ builtin_usage ();
+ return (EX_USAGE);
+#endif
case 'p':
if (local_var == 0)
pflag++;
@@ -162,6 +190,25 @@ declare_internal (list, local_var)
*flags |= att_exported;
array_needs_making = 1;
break;
+#if defined (CASEMOD_ATTRS)
+# if defined (CASEMOD_CAPCASE)
+ case 'c':
+ *flags |= att_capcase;
+ if (flags == &flags_on)
+ flags_off |= att_uppercase|att_lowercase;
+ break;
+# endif
+ case 'l':
+ *flags |= att_lowercase;
+ if (flags == &flags_on)
+ flags_off |= att_capcase|att_uppercase;
+ break;
+ case 'u':
+ *flags |= att_uppercase;
+ if (flags == &flags_on)
+ flags_off |= att_capcase|att_lowercase;
+ break;
+#endif /* CASEMOD_ATTRS */
default:
builtin_usage ();
return (EX_USAGE);
@@ -172,7 +219,7 @@ declare_internal (list, local_var)
/* If there are no more arguments left, then we just want to show
some variables. */
- if (list == 0) /* declare -[afFirtx] */
+ if (list == 0) /* declare -[aAfFirtx] */
{
/* Show local variables defined at this context level if this is
the `local' builtin. */
@@ -191,19 +238,17 @@ declare_internal (list, local_var)
free (vlist);
}
}
+ else if (pflag && (flags_on == 0 || flags_on == att_function))
+ show_all_var_attributes (flags_on == 0, nodefs);
+ else if (flags_on == 0)
+ return (set_builtin ((WORD_LIST *)NULL));
else
- {
- if (flags_on == 0)
- set_builtin ((WORD_LIST *)NULL);
- else
- set_or_show_attributes ((WORD_LIST *)NULL, flags_on, nodefs);
- }
+ set_or_show_attributes ((WORD_LIST *)NULL, flags_on, nodefs);
- fflush (stdout);
- return (EXECUTION_SUCCESS);
+ return (sh_chkwrite (EXECUTION_SUCCESS));
}
- if (pflag) /* declare -p [-afFirtx] name [name...] */
+ if (pflag) /* declare -p [-aAfFirtx] name [name...] */
{
for (any_failed = 0; list; list = list->next)
{
@@ -214,13 +259,13 @@ declare_internal (list, local_var)
any_failed++;
}
}
- return (any_failed ? EXECUTION_FAILURE : EXECUTION_SUCCESS);
+ return (sh_chkwrite (any_failed ? EXECUTION_FAILURE : EXECUTION_SUCCESS));
}
#define NEXT_VARIABLE() free (name); list = list->next; continue
/* There are arguments left, so we are making variables. */
- while (list) /* declare [-afFirx] name [name ...] */
+ while (list) /* declare [-aAfFirx] name [name ...] */
{
char *value, *name;
int offset, aflags;
@@ -232,7 +277,7 @@ declare_internal (list, local_var)
offset = assignment (name, 0);
aflags = 0;
- if (offset) /* declare [-afFirx] name=value */
+ if (offset) /* declare [-aAfFirx] name=value */
{
name[offset] = '\0';
value = name + offset + 1;
@@ -250,6 +295,13 @@ declare_internal (list, local_var)
subscript_start = (char *)NULL;
if (t = strchr (name, '[')) /* ] */
{
+ /* If offset != 0 we have already validated any array reference */
+ if (offset == 0 && valid_array_reference (name) == 0)
+ {
+ sh_invalidid (name);
+ assign_error++;
+ NEXT_VARIABLE ();
+ }
subscript_start = t;
*t = '\0';
making_array_special = 1;
@@ -279,7 +331,9 @@ declare_internal (list, local_var)
if (variable_context && ((flags_on & att_function) == 0))
{
#if defined (ARRAY_VARS)
- if ((flags_on & att_array) || making_array_special)
+ if (flags_on & att_assoc)
+ var = make_local_assoc_variable (name);
+ else if ((flags_on & att_array) || making_array_special)
var = make_local_array_variable (name);
else
#endif
@@ -336,8 +390,9 @@ declare_internal (list, local_var)
#endif /* DEBUGGER */
{
t = nodefs ? var->name
- : named_function_string (name, function_cell (var), 1);
+ : named_function_string (name, function_cell (var), FUNC_MULTILINE|FUNC_EXTERNAL);
printf ("%s\n", t);
+ any_failed = sh_chkwrite (any_failed);
}
}
else /* declare -[fF] -[rx] name [name...] */
@@ -351,7 +406,7 @@ declare_internal (list, local_var)
NEXT_VARIABLE ();
}
}
- else /* declare -[airx] name [name...] */
+ else /* declare -[aAirx] name [name...] */
{
/* Non-null if we just created or fetched a local variable. */
if (var == 0)
@@ -360,11 +415,20 @@ declare_internal (list, local_var)
if (var == 0)
{
#if defined (ARRAY_VARS)
- if ((flags_on & att_array) || making_array_special)
+ if (flags_on & att_assoc)
+ var = make_new_assoc_variable (name);
+ else if ((flags_on & att_array) || making_array_special)
var = make_new_array_variable (name);
else
#endif
- var = bind_variable (name, "", 0);
+
+ if (offset)
+ var = bind_variable (name, "", 0);
+ else
+ {
+ var = bind_variable (name, (char *)NULL, 0);
+ VSETATTR (var, att_invisible);
+ }
}
/* Cannot use declare +r to turn off readonly attribute. */
@@ -386,30 +450,48 @@ declare_internal (list, local_var)
}
#if defined (ARRAY_VARS)
- if ((making_array_special || (flags_on & att_array) || array_p (var)) && offset)
+ if ((making_array_special || (flags_on & (att_array|att_assoc)) || array_p (var) || assoc_p (var)) && offset)
{
int vlen;
vlen = STRLEN (value);
-#if 0
- if (value[0] == '(' && strchr (value, ')'))
-#else
+
if (value[0] == '(' && value[vlen-1] == ')')
-#endif
compound_array_assign = 1;
else
simple_array_assign = 1;
}
- /* Cannot use declare +a name to remove an array variable. */
- if ((flags_off & att_array) && array_p (var))
+ /* Cannot use declare +a name or declare +A name to remove an
+ array variable. */
+ if (((flags_off & att_array) && array_p (var)) || ((flags_off & att_assoc) && assoc_p (var)))
{
builtin_error (_("%s: cannot destroy array variables in this way"), name);
any_failed++;
NEXT_VARIABLE ();
}
- /* declare -a name makes name an array variable. */
- if ((making_array_special || (flags_on & att_array)) && array_p (var) == 0)
+ if ((flags_on & att_array) && assoc_p (var))
+ {
+ builtin_error (_("%s: cannot convert associative to indexed array"), name);
+ any_failed++;
+ NEXT_VARIABLE ();
+ }
+ if ((flags_on & att_assoc) && array_p (var))
+ {
+ builtin_error (_("%s: cannot convert indexed to associative array"), name);
+ any_failed++;
+ NEXT_VARIABLE ();
+ }
+
+ /* declare -A name[[n]] makes name an associative array variable. */
+ if (flags_on & att_assoc)
+ {
+ if (assoc_p (var) == 0)
+ var = convert_var_to_assoc (var);
+ }
+ /* declare -a name[[n]] or declare name[n] makes name an indexed
+ array variable. */
+ else if ((making_array_special || (flags_on & att_array)) && array_p (var) == 0 && assoc_p (var) == 0)
var = convert_var_to_array (var);
#endif /* ARRAY_VARS */
@@ -421,14 +503,19 @@ declare_internal (list, local_var)
assign_array_var_from_string (var, value, aflags);
else if (simple_array_assign && subscript_start)
{
- /* declare [-a] name[N]=value */
+ /* declare [-aA] name[N]=value */
*subscript_start = '['; /* ] */
var = assign_array_element (name, value, 0); /* XXX - not aflags */
*subscript_start = '\0';
}
else if (simple_array_assign)
- /* let bind_array_variable take care of this. */
- bind_array_variable (name, 0, value, aflags);
+ {
+ /* let bind_{array,assoc}_variable take care of this. */
+ if (assoc_p (var))
+ bind_assoc_variable (var, name, "0", value, aflags);
+ else
+ bind_array_variable (name, 0, value, aflags);
+ }
else
#endif
/* bind_variable_value duplicates the essential internals of
diff --git a/builtins/echo.def b/builtins/echo.def
index 923c43a..62c6199 100644
--- a/builtins/echo.def
+++ b/builtins/echo.def
@@ -1,23 +1,22 @@
This file is echo.def, from which is created echo.c.
It implements the builtin "echo" in Bash.
-Copyright (C) 1987-2002 Free Software Foundation, Inc.
+Copyright (C) 1987-2009 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 2, or (at your option) any later
-version.
+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.
+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; see the file COPYING. If not, write to the Free Software
-Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
+You should have received a copy of the GNU General Public License
+along with Bash. If not, see <http://www.gnu.org/licenses/>.
$PRODUCES echo.c
#include <config.h>
@@ -37,31 +36,48 @@ $BUILTIN echo
$FUNCTION echo_builtin
$DEPENDS_ON V9_ECHO
$SHORT_DOC echo [-neE] [arg ...]
-Output the ARGs. If -n is specified, the trailing newline is
-suppressed. If the -e option is given, interpretation of the
-following backslash-escaped characters is turned on:
- \a alert (bell)
- \b backspace
- \c suppress trailing newline
- \E escape character
- \f form feed
- \n new line
- \r carriage return
- \t horizontal tab
- \v vertical tab
- \\ backslash
- \0nnn the character whose ASCII code is NNN (octal). NNN can be
- 0 to 3 octal digits
-
-You can explicitly turn off the interpretation of the above characters
-with the -E option.
+Write arguments to the standard output.
+
+Display the ARGs on the standard output followed by a newline.
+
+Options:
+ -n do not append a newline
+ -e enable interpretation of the following backslash escapes
+ -E explicitly suppress interpretation of backslash escapes
+
+`echo' interprets the following backslash-escaped characters:
+ \a alert (bell)
+ \b backspace
+ \c suppress further output
+ \e escape character
+ \f form feed
+ \n new line
+ \r carriage return
+ \t horizontal tab
+ \v vertical tab
+ \\ backslash
+ \0nnn the character whose ASCII code is NNN (octal). NNN can be
+ 0 to 3 octal digits
+ \xHH the eight-bit character whose value is HH (hexadecimal). HH
+ can be one or two hex digits
+
+Exit Status:
+Returns success unless a write error occurs.
$END
$BUILTIN echo
$FUNCTION echo_builtin
$DEPENDS_ON !V9_ECHO
$SHORT_DOC echo [-n] [arg ...]
-Output the ARGs. If -n is specified, the trailing newline is suppressed.
+Write arguments to the standard output.
+
+Display the ARGs on the standard output followed by a newline.
+
+Options:
+ -n do not append a newline
+
+Exit Status:
+Returns success unless a write error occurs.
$END
#if defined (V9_ECHO)
@@ -143,6 +159,7 @@ just_echo:
clearerr (stdout); /* clear error before writing and testing success */
+ terminate_immediately++;
while (list)
{
i = len = 0;
@@ -175,12 +192,7 @@ just_echo:
if (display_return)
putchar ('\n');
- fflush (stdout);
- if (ferror (stdout))
- {
- sh_wrerror ();
- clearerr (stdout);
- return (EXECUTION_FAILURE);
- }
- return (EXECUTION_SUCCESS);
+
+ terminate_immediately--;
+ return (sh_chkwrite (EXECUTION_SUCCESS));
}
diff --git a/builtins/enable.def b/builtins/enable.def
index 823c38f..40cbb44 100644
--- a/builtins/enable.def
+++ b/builtins/enable.def
@@ -1,42 +1,51 @@
This file is enable.def, from which is created enable.c.
It implements the builtin "enable" in Bash.
-Copyright (C) 1987-2003 Free Software Foundation, Inc.
+Copyright (C) 1987-2009 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 2, or (at your option) any later
-version.
+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.
+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; see the file COPYING. If not, write to the Free Software
-Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
+You should have received a copy of the GNU General Public License
+along with Bash. If not, see <http://www.gnu.org/licenses/>.
$PRODUCES enable.c
$BUILTIN enable
$FUNCTION enable_builtin
-$SHORT_DOC enable [-pnds] [-a] [-f filename] [name ...]
-Enable and disable builtin shell commands. This allows
-you to use a disk command which has the same name as a shell
-builtin without specifying a full pathname. If -n is used, the
-NAMEs become disabled; otherwise NAMEs are enabled. For example,
-to use the `test' found in $PATH instead of the shell builtin
-version, type `enable -n test'. On systems supporting dynamic
-loading, the -f option may be used to load new builtins from the
-shared object FILENAME. The -d option will delete a builtin
-previously loaded with -f. If no non-option names are given, or
-the -p option is supplied, a list of builtins is printed. The
--a option means to print every builtin with an indication of whether
-or not it is enabled. The -s option restricts the output to the POSIX.2
-`special' builtins. The -n option displays a list of all disabled builtins.
+$SHORT_DOC enable [-a] [-dnps] [-f filename] [name ...]
+Enable and disable shell builtins.
+
+Enables and disables builtin shell commands. Disabling allows you to
+execute a disk command which has the same name as a shell builtin
+without using a full pathname.
+
+Options:
+ -a print a list of builtins showing whether or not each is enabled
+ -n disable each NAME or display a list of disabled builtins
+ -p print the list of builtins in a reusable format
+ -s print only the names of Posix `special' builtins
+
+Options controlling dynamic loading:
+ -f Load builtin NAME from shared object FILENAME
+ -d Remove a builtin loaded with -f
+
+Without options, each NAME is enabled.
+
+To use the `test' found in $PATH instead of the shell builtin
+version, type `enable -n test'.
+
+Exit Status:
+Returns success unless NAME is not a shell builtin or an error occurs.
$END
#include <config.h>
diff --git a/builtins/eval.def b/builtins/eval.def
index 500e8c7..ee9a23d 100644
--- a/builtins/eval.def
+++ b/builtins/eval.def
@@ -1,30 +1,35 @@
This file is eval.def, from which is created eval.c.
It implements the builtin "eval" in Bash.
-Copyright (C) 1987-2002 Free Software Foundation, Inc.
+Copyright (C) 1987-2009 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 2, or (at your option) any later
-version.
+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.
+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; see the file COPYING. If not, write to the Free Software
-Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
+You should have received a copy of the GNU General Public License
+along with Bash. If not, see <http://www.gnu.org/licenses/>.
$PRODUCES eval.c
$BUILTIN eval
$FUNCTION eval_builtin
$SHORT_DOC eval [arg ...]
-Read ARGs as input to the shell and execute the resulting command(s).
+Execute arguments as a shell command.
+
+Combine ARGs into a single string, use the result as input to the shell,
+and execute the resulting commands.
+
+Exit Status:
+Returns exit status of command or success if command is null.
$END
#include <config.h>
diff --git a/builtins/evalfile.c b/builtins/evalfile.c
index d05bc7b..972d039 100644
--- a/builtins/evalfile.c
+++ b/builtins/evalfile.c
@@ -1,20 +1,22 @@
-/* Copyright (C) 1996-2003 Free Software Foundation, Inc.
+/* evalfile.c - read and evaluate commands from a file or file descriptor */
+
+/* Copyright (C) 1996-2009 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 2, or (at your option) any later
- version.
+ 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.
- 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; see the file COPYING. If not, write to the Free Software
- Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
+ 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>
@@ -45,6 +47,8 @@
# include "../bashhist.h"
#endif
+#include <typemax.h>
+
#include "common.h"
#if !defined (errno)
@@ -77,7 +81,8 @@ _evalfile (filename, flags)
{
volatile int old_interactive;
procenv_t old_return_catch;
- int return_val, fd, result, pflags;
+ int return_val, fd, result, pflags, i, nnull;
+ ssize_t nr; /* return value from read(2) */
char *string;
struct stat finfo;
size_t file_size;
@@ -147,34 +152,60 @@ file_error_and_exit:
setmode (fd, O_TEXT);
#endif
- string = (char *)xmalloc (1 + file_size);
- result = read (fd, string, file_size);
- string[result] = '\0';
+ if (S_ISREG (finfo.st_mode) && file_size <= SSIZE_MAX)
+ {
+ string = (char *)xmalloc (1 + file_size);
+ nr = read (fd, string, file_size);
+ if (nr >= 0)
+ string[nr] = '\0';
+ }
+ else
+ nr = zmapfd (fd, &string, 0);
return_val = errno;
close (fd);
errno = return_val;
- if (result < 0) /* XXX was != file_size, not < 0 */
+ if (nr < 0) /* XXX was != file_size, not < 0 */
{
free (string);
goto file_error_and_exit;
}
- if (result == 0)
+ if (nr == 0)
{
free (string);
return ((flags & FEVAL_BUILTIN) ? EXECUTION_SUCCESS : 1);
}
if ((flags & FEVAL_CHECKBINARY) &&
- check_binary_file (string, (result > 80) ? 80 : result))
+ check_binary_file (string, (nr > 80) ? 80 : nr))
{
free (string);
- (*errfunc) ("%s: cannot execute binary file", filename);
+ (*errfunc) (_("%s: cannot execute binary file"), filename);
return ((flags & FEVAL_BUILTIN) ? EX_BINARY_FILE : -1);
}
+ i = strlen (string);
+ if (i < nr)
+ {
+ for (nnull = i = 0; i < nr; i++)
+ if (string[i] == '\0')
+ {
+ memmove (string+i, string+i+1, nr - i);
+ nr--;
+ /* Even if the `check binary' flag is not set, we want to avoid
+ sourcing files with more than 256 null characters -- that
+ probably indicates a binary file. */
+ if ((flags & FEVAL_BUILTIN) && ++nnull > 256)
+ {
+ free (string);
+ (*errfunc) (_("%s: cannot execute binary file"), filename);
+ return ((flags & FEVAL_BUILTIN) ? EX_BINARY_FILE : -1);
+ }
+ }
+ }
+
if (flags & FEVAL_UNWINDPROT)
{
begin_unwind_frame ("_evalfile");
diff --git a/builtins/evalstring.c b/builtins/evalstring.c
index 36f0ad3..40abe00 100644
--- a/builtins/evalstring.c
+++ b/builtins/evalstring.c
@@ -1,22 +1,22 @@
-/* Evaluate a string as one or more shell commands.
+/* evalstring.c - evaluate a string as one or more shell commands.
- Copyright (C) 1996-2005 Free Software Foundation, Inc.
+/* Copyright (C) 1996-2009 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 2, or (at your option) any later
- version.
+ 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; see the file COPYING. If not, write to the Free Software
- Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
+ 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>
@@ -43,12 +43,16 @@
#include "../execute_cmd.h"
#include "../redir.h"
#include "../trap.h"
+#include "../bashintl.h"
+
+#include <y.tab.h>
#if defined (HISTORY)
# include "../bashhist.h"
#endif
#include "common.h"
+#include "builtext.h"
#if !defined (errno)
extern int errno;
@@ -58,15 +62,30 @@ extern int errno;
extern int indirection_level, subshell_environment;
extern int line_number;
+extern int current_token, shell_eof_token;
extern int last_command_exit_value;
extern int running_trap;
extern int loop_level;
+extern int executing_list;
+extern int comsub_ignore_return;
extern int posixly_correct;
+extern sh_builtin_func_t *this_shell_builtin;
int parse_and_execute_level = 0;
static int cat_file __P((REDIRECT *));
+#define PE_TAG "parse_and_execute top"
+#define PS_TAG "parse_string top"
+
+#if defined (HISTORY)
+static void
+set_history_remembering ()
+{
+ remember_on_history = enable_history_list;
+}
+#endif
+
/* How to force parse_and_execute () to clean up after itself. */
void
parse_and_execute_cleanup ()
@@ -76,51 +95,43 @@ parse_and_execute_cleanup ()
run_trap_cleanup (running_trap - 1);
unfreeze_jobs_list ();
}
- run_unwind_frame ("parse_and_execute_top");
-}
-/* Parse and execute the commands in STRING. Returns whatever
- execute_command () returns. This frees STRING. FLAGS is a
- flags word; look in common.h for the possible values. Actions
- are:
- (flags & SEVAL_NONINT) -> interactive = 0;
- (flags & SEVAL_INTERACT) -> interactive = 1;
- (flags & SEVAL_NOHIST) -> call bash_history_disable ()
- (flags & SEVAL_NOFREE) -> don't free STRING when finished
- (flags & SEVAL_RESETLINE) -> reset line_number to 1
-*/
+ if (have_unwind_protects ())
+ run_unwind_frame (PE_TAG);
+ else
+ parse_and_execute_level = 0; /* XXX */
+}
-int
-parse_and_execute (string, from_file, flags)
+static void
+parse_prologue (string, flags, tag)
char *string;
- const char *from_file;
int flags;
+ char *tag;
{
- int code, x, lreset;
- volatile int should_jump_to_top_level, last_result;
char *orig_string;
- COMMAND *volatile command;
+ int x;
orig_string = string;
/* Unwind protect this invocation of parse_and_execute (). */
- begin_unwind_frame ("parse_and_execute_top");
+ begin_unwind_frame (tag);
unwind_protect_int (parse_and_execute_level);
unwind_protect_jmp_buf (top_level);
unwind_protect_int (indirection_level);
unwind_protect_int (line_number);
unwind_protect_int (loop_level);
+ unwind_protect_int (executing_list);
+ unwind_protect_int (comsub_ignore_return);
if (flags & (SEVAL_NONINT|SEVAL_INTERACT))
unwind_protect_int (interactive);
- lreset = flags & SEVAL_RESETLINE;
-
#if defined (HISTORY)
- unwind_protect_int (remember_on_history); /* can be used in scripts */
+ if (parse_and_execute_level == 0)
+ add_unwind_protect (set_history_remembering, (char *)NULL);
+ else
+ unwind_protect_int (remember_on_history); /* can be used in scripts */
# if defined (BANG_HISTORY)
if (interactive_shell)
- {
- unwind_protect_int (history_expansion_inhibited);
- }
+ unwind_protect_int (history_expansion_inhibited);
# endif /* BANG_HISTORY */
#endif /* HISTORY */
@@ -135,8 +146,42 @@ parse_and_execute (string, from_file, flags)
add_unwind_protect (xfree, orig_string);
end_unwind_frame ();
+ if (flags & (SEVAL_NONINT|SEVAL_INTERACT))
+ interactive = (flags & SEVAL_NONINT) ? 0 : 1;
+
+#if defined (HISTORY)
+ if (flags & SEVAL_NOHIST)
+ bash_history_disable ();
+#endif /* HISTORY */
+}
+
+/* Parse and execute the commands in STRING. Returns whatever
+ execute_command () returns. This frees STRING. FLAGS is a
+ flags word; look in common.h for the possible values. Actions
+ are:
+ (flags & SEVAL_NONINT) -> interactive = 0;
+ (flags & SEVAL_INTERACT) -> interactive = 1;
+ (flags & SEVAL_NOHIST) -> call bash_history_disable ()
+ (flags & SEVAL_NOFREE) -> don't free STRING when finished
+ (flags & SEVAL_RESETLINE) -> reset line_number to 1
+*/
+
+int
+parse_and_execute (string, from_file, flags)
+ char *string;
+ const char *from_file;
+ int flags;
+{
+ int code, lreset;
+ volatile int should_jump_to_top_level, last_result;
+ COMMAND *volatile command;
+
+ parse_prologue (string, flags, PE_TAG);
+
parse_and_execute_level++;
+ lreset = flags & SEVAL_RESETLINE;
+
/* Reset the line number if the caller wants us to. If we don't reset the
line number, we have to subtract one, because we will add one just
before executing the next command (resetting the line number sets it to
@@ -146,13 +191,6 @@ parse_and_execute (string, from_file, flags)
line_number--;
indirection_level++;
- if (flags & (SEVAL_NONINT|SEVAL_INTERACT))
- interactive = (flags & SEVAL_NONINT) ? 0 : 1;
-
-#if defined (HISTORY)
- if (flags & SEVAL_NOHIST)
- bash_history_disable ();
-#endif /* HISTORY */
code = should_jump_to_top_level = 0;
last_result = EXECUTION_SUCCESS;
@@ -213,7 +251,7 @@ parse_and_execute (string, from_file, flags)
if (parse_command () == 0)
{
- if (interactive_shell == 0 && read_but_dont_execute)
+ if ((flags & SEVAL_PARSEONLY) || (interactive_shell == 0 && read_but_dont_execute))
{
last_result = EXECUTION_SUCCESS;
dispose_command (global_command);
@@ -230,6 +268,9 @@ parse_and_execute (string, from_file, flags)
global_command = (COMMAND *)NULL;
+ if ((subshell_environment & SUBSHELL_COMSUB) && comsub_ignore_return)
+ command->flags |= CMD_IGNORE_RETURN;
+
#if defined (ONESHOT)
/*
* IF
@@ -237,6 +278,7 @@ parse_and_execute (string, from_file, flags)
* parse_and_execute has not been called recursively AND
* we're not running a trap AND
* we have parsed the full command (string == '\0') AND
+ * we're not going to run the exit trap AND
* we have a simple command without redirections AND
* the command is not being timed AND
* the command's return status is not being inverted
@@ -247,7 +289,8 @@ parse_and_execute (string, from_file, flags)
running_trap == 0 &&
*bash_input.location.string == '\0' &&
command->type == cm_simple &&
- !command->redirects && !command->value.Simple->redirects &&
+ signal_is_trapped (EXIT_TRAP) == 0 &&
+ command->redirects == 0 && command->value.Simple->redirects == 0 &&
((command->flags & CMD_TIME_PIPELINE) == 0) &&
((command->flags & CMD_INVERT_RETURN) == 0))
{
@@ -284,6 +327,19 @@ parse_and_execute (string, from_file, flags)
{
last_result = EXECUTION_FAILURE;
+ if (interactive_shell == 0 && this_shell_builtin &&
+ (this_shell_builtin == source_builtin || this_shell_builtin == eval_builtin) &&
+ last_command_exit_value == EX_BADSYNTAX && posixly_correct)
+ {
+#if 0 /* XXX - for bash-4.2 */
+ should_jump_to_top_level = 1;
+ code = ERREXIT;
+ last_command_exit_value = EX_BADUSAGE;
+#else
+ internal_warning (_("syntax errors in . or eval will cause future versions of the shell to abort as Posix requires"));
+#endif
+ }
+
/* Since we are shell compatible, syntax errors in a script
abort the execution of the script. Right? */
break;
@@ -292,7 +348,7 @@ parse_and_execute (string, from_file, flags)
out:
- run_unwind_frame ("parse_and_execute_top");
+ run_unwind_frame (PE_TAG);
if (interrupt_state && parse_and_execute_level == 0)
{
@@ -309,6 +365,110 @@ parse_and_execute (string, from_file, flags)
return (last_result);
}
+/* Parse a command contained in STRING according to FLAGS and return the
+ number of characters consumed from the string. If non-NULL, set *ENDP
+ to the position in the string where the parse ended. Used to validate
+ command substitutions during parsing to obey Posix rules about finding
+ the end of the command and balancing parens. */
+int
+parse_string (string, from_file, flags, endp)
+ char *string;
+ const char *from_file;
+ int flags;
+ char **endp;
+{
+ int code, nc;
+ volatile int should_jump_to_top_level;
+ COMMAND *volatile command, *oglobal;
+ char *ostring;
+
+ parse_prologue (string, flags, PS_TAG);
+
+ /* Reset the line number if the caller wants us to. If we don't reset the
+ line number, we have to subtract one, because we will add one just
+ before executing the next command (resetting the line number sets it to
+ 0; the first line number is 1). */
+ push_stream (0);
+
+ code = should_jump_to_top_level = 0;
+ oglobal = global_command;
+ ostring = string;
+
+ with_input_from_string (string, from_file);
+ while (*(bash_input.location.string))
+ {
+ command = (COMMAND *)NULL;
+
+#if 0
+ if (interrupt_state)
+ break;
+#endif
+
+ /* Provide a location for functions which `longjmp (top_level)' to
+ jump to. */
+ code = setjmp (top_level);
+
+ if (code)
+ {
+#if defined (DEBUG)
+itrace("parse_string: longjmp executed: code = %d", code);
+#endif
+ should_jump_to_top_level = 0;
+ switch (code)
+ {
+ case FORCE_EOF:
+ case ERREXIT:
+ case EXITPROG:
+ case DISCARD: /* XXX */
+ if (command)
+ dispose_command (command);
+ /* Remember to call longjmp (top_level) after the old
+ value for it is restored. */
+ should_jump_to_top_level = 1;
+ goto out;
+
+ default:
+ command_error ("parse_string", CMDERR_BADJUMP, code, 0);
+ break;
+ }
+ }
+
+ if (parse_command () == 0)
+ {
+ dispose_command (global_command);
+ global_command = (COMMAND *)NULL;
+ }
+ else
+ {
+ if ((flags & SEVAL_NOLONGJMP) == 0)
+ {
+ should_jump_to_top_level = 1;
+ code = DISCARD;
+ }
+ else
+ reset_parser (); /* XXX - sets token_to_read */
+ break;
+ }
+
+ if (current_token == yacc_EOF || current_token == shell_eof_token)
+ break;
+ }
+
+ out:
+
+ global_command = oglobal;
+ nc = bash_input.location.string - ostring;
+ if (endp)
+ *endp = bash_input.location.string;
+
+ run_unwind_frame (PS_TAG);
+
+ if (should_jump_to_top_level)
+ jump_to_top_level (code);
+
+ return (nc);
+}
+
/* Handle a $( < file ) command substitution. This expands the filename,
returning errors as appropriate, then just cats the file to the standard
output. */
diff --git a/builtins/exec.def b/builtins/exec.def
index 0818a25..0837a98 100644
--- a/builtins/exec.def
+++ b/builtins/exec.def
@@ -1,37 +1,44 @@
This file is exec.def, from which is created exec.c.
It implements the builtin "exec" in Bash.
-Copyright (C) 1987-2003 Free Software Foundation, Inc.
+Copyright (C) 1987-2009 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 2, or (at your option) any later
-version.
+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.
+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; see the file COPYING. If not, write to the Free Software
-Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
+You should have received a copy of the GNU General Public License
+along with Bash. If not, see <http://www.gnu.org/licenses/>.
$PRODUCES exec.c
$BUILTIN exec
$FUNCTION exec_builtin
-$SHORT_DOC exec [-cl] [-a name] file [redirection ...]
-Exec FILE, replacing this shell with the specified program.
-If FILE is not specified, the redirections take effect in this
-shell. If the first argument is `-l', then place a dash in the
-zeroth arg passed to FILE, as login does. If the `-c' option
-is supplied, FILE is executed with a null environment. The `-a'
-option means to make set argv[0] of the executed process to NAME.
-If the file cannot be executed and the shell is not interactive,
-then the shell exits, unless the shell option `execfail' is set.
+$SHORT_DOC exec [-cl] [-a name] [command [arguments ...]] [redirection ...]
+Replace the shell with the given command.
+
+Execute COMMAND, replacing this shell with the specified program.
+ARGUMENTS become the arguments to COMMAND. If COMMAND is not specified,
+any redirections take effect in the current shell.
+
+Options:
+ -a name pass NAME as the zeroth argument to COMMAND
+ -c execute COMMAND with an empty environment
+ -l place a dash in the zeroth argument to COMMAND
+
+If the command cannot be executed, a non-interactive shell exits, unless
+the shell option `execfail' is set.
+
+Exit Status:
+Returns success unless COMMAND is not found or a redirection error occurs.
$END
#include <config.h>
diff --git a/builtins/exit.def b/builtins/exit.def
index ddaa5d3..34728eb 100644
--- a/builtins/exit.def
+++ b/builtins/exit.def
@@ -1,30 +1,31 @@
This file is exit.def, from which is created exit.c.
It implements the builtins "exit", and "logout" in Bash.
-Copyright (C) 1987-2005 Free Software Foundation, Inc.
+Copyright (C) 1987-2009 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 2, or (at your option) any later
-version.
+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.
+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; see the file COPYING. If not, write to the Free Software
-Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
+You should have received a copy of the GNU General Public License
+along with Bash. If not, see <http://www.gnu.org/licenses/>.
$PRODUCES exit.c
$BUILTIN exit
$FUNCTION exit_builtin
$SHORT_DOC exit [n]
-Exit the shell with a status of N. If N is omitted, the exit status
+Exit the shell.
+
+Exits the shell with a status of N. If N is omitted, the exit status
is that of the last command executed.
$END
@@ -45,6 +46,7 @@ $END
#include "common.h"
#include "builtext.h" /* for jobs_builtin */
+extern int check_jobs_at_exit;
extern int last_command_exit_value;
extern int running_trap, trap_saved_exit_value;
extern int subshell_environment;
@@ -60,7 +62,7 @@ exit_builtin (list)
{
if (interactive)
{
- fprintf (stderr, login_shell ? "logout\n" : "exit\n");
+ fprintf (stderr, login_shell ? _("logout\n") : "exit\n");
fflush (stderr);
}
@@ -69,8 +71,11 @@ exit_builtin (list)
$BUILTIN logout
$FUNCTION logout_builtin
-$SHORT_DOC logout
-Logout of a login shell.
+$SHORT_DOC logout [n]
+Exit a login shell.
+
+Exits a login shell with exit status N. Returns an error if not executed
+in a login shell.
$END
/* How to logout. */
@@ -94,7 +99,7 @@ exit_or_logout (list)
int exit_value;
#if defined (JOB_CONTROL)
- int exit_immediate_okay;
+ int exit_immediate_okay, stopmsg;
exit_immediate_okay = (interactive == 0 ||
last_shell_builtin == exit_builtin ||
@@ -102,21 +107,32 @@ exit_or_logout (list)
last_shell_builtin == jobs_builtin);
/* Check for stopped jobs if the user wants to. */
- if (!exit_immediate_okay)
+ if (exit_immediate_okay == 0)
{
register int i;
- for (i = 0; i < js.j_jobslots; i++)
+ for (i = stopmsg = 0; i < js.j_jobslots; i++)
if (jobs[i] && STOPPED (i))
- {
- fprintf (stderr, _("There are stopped jobs.\n"));
-
- /* This is NOT superfluous because EOF can get here without
- going through the command parser. Set both last and this
- so that either `exit', `logout', or ^D will work to exit
- immediately if nothing intervenes. */
- this_shell_builtin = last_shell_builtin = exit_builtin;
- return (EXECUTION_FAILURE);
- }
+ stopmsg = JSTOPPED;
+ else if (check_jobs_at_exit && stopmsg == 0 && jobs[i] && RUNNING (i))
+ stopmsg = JRUNNING;
+
+ if (stopmsg == JSTOPPED)
+ fprintf (stderr, _("There are stopped jobs.\n"));
+ else if (stopmsg == JRUNNING)
+ fprintf (stderr, _("There are running jobs.\n"));
+
+ if (stopmsg && check_jobs_at_exit)
+ list_all_jobs (JLIST_STANDARD);
+
+ if (stopmsg)
+ {
+ /* This is NOT superfluous because EOF can get here without
+ going through the command parser. Set both last and this
+ so that either `exit', `logout', or ^D will work to exit
+ immediately if nothing intervenes. */
+ this_shell_builtin = last_shell_builtin = exit_builtin;
+ return (EXECUTION_FAILURE);
+ }
}
#endif /* JOB_CONTROL */
diff --git a/builtins/fc.def b/builtins/fc.def
index 5ab5308..a378d9d 100644
--- a/builtins/fc.def
+++ b/builtins/fc.def
@@ -1,48 +1,52 @@
This file is fc.def, from which is created fc.c.
It implements the builtin "fc" in Bash.
-Copyright (C) 1987-2005 Free Software Foundation, Inc.
+Copyright (C) 1987-2009 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 2, or (at your option) any later
-version.
+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.
+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; see the file COPYING. If not, write to the Free Software
-Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
+You should have received a copy of the GNU General Public License
+along with Bash. If not, see <http://www.gnu.org/licenses/>.
$PRODUCES fc.c
$BUILTIN fc
$FUNCTION fc_builtin
$DEPENDS_ON HISTORY
-$SHORT_DOC fc [-e ename] [-nlr] [first] [last] or fc -s [pat=rep] [cmd]
+$SHORT_DOC fc [-e ename] [-lnr] [first] [last] or fc -s [pat=rep] [command]
+Display or execute commands from the history list.
+
fc is used to list or edit and re-execute commands from the history list.
FIRST and LAST can be numbers specifying the range, or FIRST can be a
string, which means the most recent command beginning with that
string.
- -e ENAME selects which editor to use. Default is FCEDIT, then EDITOR,
- then vi.
-
- -l means list lines instead of editing.
- -n means no line numbers listed.
- -r means reverse the order of the lines (making it newest listed first).
+Options:
+ -e ENAME select which editor to use. Default is FCEDIT, then EDITOR,
+ then vi
+ -l list lines instead of editing
+ -n omit line numbers when listing
+ -r reverse the order of the lines (newest listed first)
-With the `fc -s [pat=rep ...] [command]' format, the command is
+With the `fc -s [pat=rep ...] [command]' format, COMMAND is
re-executed after the substitution OLD=NEW is performed.
A useful alias to use with this is r='fc -s', so that typing `r cc'
runs the last command beginning with `cc' and typing `r' re-executes
the last command.
+
+Exit Status:
+Returns success or status of executed command; non-zero if an error occurs.
$END
#include <config.h>
@@ -84,11 +88,11 @@ extern int errno;
extern int current_command_line_count;
extern int literal_history;
extern int posixly_correct;
+extern int subshell_environment, interactive_shell;
extern int unlink __P((const char *));
extern FILE *sh_mktmpfp __P((char *, int, char **));
-extern int delete_last_history __P((void));
/* **************************************************************** */
/* */
@@ -155,11 +159,11 @@ static void fc_addhist __P((char *));
#endif
/* String to execute on a file that we want to edit. */
-#define FC_EDIT_COMMAND "${FCEDIT:-${EDITOR:-$(command -v editor || echo vi)}}"
+#define FC_EDIT_COMMAND "${FCEDIT:-${EDITOR:-vi}}"
#if defined (STRICT_POSIX)
# define POSIX_FC_EDIT_COMMAND "${FCEDIT:-ed}"
#else
-# define POSIX_FC_EDIT_COMMAND "${FCEDIT:-${EDITOR:-$(command -v editor || echo ed)}}"
+# define POSIX_FC_EDIT_COMMAND "${FCEDIT:-${EDITOR:-ed}}"
#endif
int
@@ -169,7 +173,7 @@ fc_builtin (list)
register int i;
register char *sep;
int numbering, reverse, listing, execute;
- int histbeg, histend, last_hist, retval, opt;
+ int histbeg, histend, last_hist, retval, opt, rh;
FILE *stream;
REPL *rlist, *rl;
char *ename, *command, *newcom, *fcedit;
@@ -272,6 +276,8 @@ fc_builtin (list)
fprintf (stderr, "%s\n", command);
fc_replhist (command); /* replace `fc -s' with command */
+ /* Posix says that the re-executed commands should be entered into the
+ history. */
return (parse_and_execute (command, "fc", SEVAL_NOHIST));
}
@@ -290,12 +296,12 @@ fc_builtin (list)
line was actually added (HISTIGNORE may have caused it to not be),
so we check hist_last_line_added. */
- /* "When not listing, he fc command that caused the editing shall not be
- entered into the history list." */
- if (listing == 0 && hist_last_line_added)
- delete_last_history ();
-
- last_hist = i - 1 - hist_last_line_added;
+ /* Even though command substitution through parse_and_execute turns off
+ remember_on_history, command substitution in a shell when set -o history
+ has been enabled (interactive or not) should use it in the last_hist
+ calculation as if it were on. */
+ rh = remember_on_history || ((subshell_environment & SUBSHELL_COMSUB) && enable_history_list);
+ last_hist = i - rh - hist_last_line_added;
if (list)
{
@@ -322,6 +328,21 @@ fc_builtin (list)
histbeg = histend = last_hist;
}
+ /* "When not listing, the fc command that caused the editing shall not be
+ entered into the history list." */
+ if (listing == 0 && hist_last_line_added)
+ {
+ bash_delete_last_history ();
+ /* If we're editing a single command -- the last command in the
+ history -- and we just removed the dummy command added by
+ edit_and_execute_command (), we need to check whether or not we
+ just removed the last command in the history and need to back
+ the pointer up. remember_on_history is off because we're running
+ in parse_and_execute(). */
+ if (histbeg == histend && histend == last_hist && hlist[last_hist] == 0)
+ last_hist = histbeg = --histend;
+ }
+
/* We print error messages for line specifications out of range. */
if ((histbeg < 0) || (histend < 0))
{
@@ -368,8 +389,15 @@ fc_builtin (list)
}
if (listing)
- return (EXECUTION_SUCCESS);
+ return (sh_chkwrite (EXECUTION_SUCCESS));
+ fflush (stream);
+ if (ferror (stream))
+ {
+ sh_wrerror ();
+ fclose (stream);
+ return (EXECUTION_FAILURE);
+ }
fclose (stream);
/* Now edit the file of commands. */
@@ -436,10 +464,11 @@ fc_gethnum (command, hlist)
char *command;
HIST_ENTRY **hlist;
{
- int sign = 1, n, clen;
+ int sign, n, clen, rh;
register int i, j;
register char *s;
+ sign = 1;
/* Count history elements. */
for (i = 0; hlist[i]; i++);
@@ -449,8 +478,14 @@ fc_gethnum (command, hlist)
and makes the last command that this deals with be the last command
the user entered before the fc. We need to check whether the
line was actually added (HISTIGNORE may have caused it to not be),
- so we check hist_last_line_added. */
- i -= 1 + hist_last_line_added;
+ so we check hist_last_line_added. This needs to agree with the
+ calculation of last_hist in fc_builtin above. */
+ /* Even though command substitution through parse_and_execute turns off
+ remember_on_history, command substitution in a shell when set -o history
+ has been enabled (interactive or not) should use it in the last_hist
+ calculation as if it were on. */
+ rh = remember_on_history || ((subshell_environment & SUBSHELL_COMSUB) && enable_history_list);
+ i -= rh + hist_last_line_added;
/* No specification defaults to most recent command. */
if (command == NULL)
@@ -601,7 +636,7 @@ fc_replhist (command)
if (command && *command)
{
- delete_last_history ();
+ bash_delete_last_history ();
maybe_add_history (command); /* Obeys HISTCONTROL setting. */
}
}
diff --git a/builtins/fg_bg.def b/builtins/fg_bg.def
index c14381b..ae7e904 100644
--- a/builtins/fg_bg.def
+++ b/builtins/fg_bg.def
@@ -1,23 +1,22 @@
This file is fg_bg.def, from which is created fg_bg.c.
It implements the builtins "bg" and "fg" in Bash.
-Copyright (C) 1987-2005 Free Software Foundation, Inc.
+Copyright (C) 1987-2009 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 2, or (at your option) any later
-version.
+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.
+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; see the file COPYING. If not, write to the Free Software
-Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
+You should have received a copy of the GNU General Public License
+along with Bash. If not, see <http://www.gnu.org/licenses/>.
$PRODUCES fg_bg.c
@@ -25,9 +24,14 @@ $BUILTIN fg
$FUNCTION fg_builtin
$DEPENDS_ON JOB_CONTROL
$SHORT_DOC fg [job_spec]
-Place JOB_SPEC in the foreground, and make it the current job. If
-JOB_SPEC is not present, the shell's notion of the current job is
-used.
+Move job to the foreground.
+
+Place the job identified by JOB_SPEC in the foreground, making it the
+current job. If JOB_SPEC is not present, the shell's notion of the
+current job is used.
+
+Exit Status:
+Status of command placed in foreground, or failure if an error occurs.
$END
#include <config.h>
@@ -83,9 +87,14 @@ $BUILTIN bg
$FUNCTION bg_builtin
$DEPENDS_ON JOB_CONTROL
$SHORT_DOC bg [job_spec ...]
-Place each JOB_SPEC in the background, as if it had been started with
-`&'. If JOB_SPEC is not present, the shell's notion of the current
-job is used.
+Move jobs to the background.
+
+Place the jobs identified by each JOB_SPEC in the background, as if they
+had been started with `&'. If JOB_SPEC is not present, the shell's notion
+of the current job is used.
+
+Exit Status:
+Returns success unless job control is not enabled or an error occurs.
$END
#if defined (JOB_CONTROL)
@@ -137,7 +146,7 @@ fg_bg (list, foreground)
if (INVALID_JOB (job))
{
if (job != DUP_JOB)
- sh_badjob (list ? list->word->word : "current");
+ sh_badjob (list ? list->word->word : _("current"));
goto failure;
}
diff --git a/builtins/getopt.c b/builtins/getopt.c
index b223a76..feb18b5 100644
--- a/builtins/getopt.c
+++ b/builtins/getopt.c
@@ -1,21 +1,22 @@
-/* getopt for BASH.
+/* getopt.c - getopt for Bash. Used by the getopt builtin. */
- Copyright (C) 1993, 1994
- Free Software Foundation, Inc.
+/* Copyright (C) 1993-2009 Free Software Foundation, Inc.
- This program 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 2, or (at your option) any
- later version.
+ This file is part of GNU Bash, the Bourne Again SHell.
- This program is distributed in the hope that it will be useful,
+ 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 this program; if not, write to the Free Software
- Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
+ along with Bash. If not, see <http://www.gnu.org/licenses/>.
+*/
#include <config.h>
diff --git a/builtins/getopt.h b/builtins/getopt.h
index 7a4afb1..75fdec5 100644
--- a/builtins/getopt.h
+++ b/builtins/getopt.h
@@ -1,19 +1,22 @@
-/* Declarations for getopt.
- Copyright (C) 1989, 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
+/* getopt.h - declarations for getopt. */
- This program 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 2, or (at your option) any
- later version.
+/* Copyright (C) 1989, 1990, 1991, 1992, 1993, 2008,2009 Free Software Foundation, Inc.
- This program is distributed in the hope that it will be useful,
+ 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 this program; if not, write to the Free Software
- Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
+ along with Bash. If not, see <http://www.gnu.org/licenses/>.
+*/
/* XXX THIS HAS BEEN MODIFIED FOR INCORPORATION INTO BASH XXX */
diff --git a/builtins/getopts.def b/builtins/getopts.def
index a9aad62..c077c8e 100644
--- a/builtins/getopts.def
+++ b/builtins/getopts.def
@@ -5,26 +5,28 @@ Copyright (C) 1987-2004 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 2, or (at your option) any later
-version.
+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.
+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; see the file COPYING. If not, write to the Free Software
-Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
+You should have received a copy of the GNU General Public License
+along with Bash. If not, see <http://www.gnu.org/licenses/>.
$PRODUCES getopts.c
$BUILTIN getopts
$FUNCTION getopts_builtin
$SHORT_DOC getopts optstring name [arg]
-Getopts is used by shell procedures to parse positional parameters.
+Parse option arguments.
+
+Getopts is used by shell procedures to parse positional parameters
+as options.
OPTSTRING contains the option letters to be recognized; if a letter
is followed by a colon, the option is expected to have an argument,
@@ -54,6 +56,10 @@ OPTSTRING is not a colon. OPTERR has the value 1 by default.
Getopts normally parses the positional parameters ($0 - $9), but if
more arguments are given, they are parsed instead.
+
+Exit Status:
+Returns success if an option is found; fails if the end of options is
+encountered or an error occurs.
$END
#include <config.h>
diff --git a/builtins/hash.def b/builtins/hash.def
index 697ffd0..7a8aced 100644
--- a/builtins/hash.def
+++ b/builtins/hash.def
@@ -1,39 +1,47 @@
This file is hash.def, from which is created hash.c.
It implements the builtin "hash" in Bash.
-Copyright (C) 1987-2006 Free Software Foundation, Inc.
+Copyright (C) 1987-2009 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 2, or (at your option) any later
-version.
+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.
+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; see the file COPYING. If not, write to the Free Software
-Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
+You should have received a copy of the GNU General Public License
+along with Bash. If not, see <http://www.gnu.org/licenses/>.
$PRODUCES hash.c
$BUILTIN hash
$FUNCTION hash_builtin
$SHORT_DOC hash [-lr] [-p pathname] [-dt] [name ...]
-For each NAME, the full pathname of the command is determined and
-remembered. If the -p option is supplied, PATHNAME is used as the
-full pathname of NAME, and no path search is performed. The -r
-option causes the shell to forget all remembered locations. The -d
-option causes the shell to forget the remembered location of each NAME.
-If the -t option is supplied the full pathname to which each NAME
-corresponds is printed. If multiple NAME arguments are supplied with
--t, the NAME is printed before the hashed full pathname. The -l option
-causes output to be displayed in a format that may be reused as input.
-If no arguments are given, information about remembered commands is displayed.
+Remember or display program locations.
+
+Determine and remember the full pathname of each command NAME. If
+no arguments are given, information about remembered commands is displayed.
+
+Options:
+ -d forget the remembered location of each NAME
+ -l display in a format that may be reused as input
+ -p pathname use PATHNAME is the full pathname of NAME
+ -r forget all remembered locations
+ -t print the remembered location of each NAME, preceding
+ each location with the corresponding NAME if multiple
+ NAMEs are given
+Arguments:
+ NAME Each NAME is searched for in $PATH and added to the list
+ of remembered commands.
+
+Exit Status:
+Returns success unless NAME is not found or an invalid option is given.
$END
#include <config.h>
@@ -158,7 +166,7 @@ hash_builtin (list)
#ifdef EISDIR
builtin_error ("%s: %s", pathname, strerror (EISDIR));
#else
- builtin_error ("%s: is a directory", pathname);
+ builtin_error (_("%s: is a directory"), pathname);
#endif
opt = EXECUTION_FAILURE;
}
@@ -233,7 +241,7 @@ print_hashed_commands (fmt)
return (0);
if (fmt == 0)
- printf ("hits\tcommand\n");
+ printf (_("hits\tcommand\n"));
hash_walk (hashed_filenames, fmt ? print_portable_hash_info : print_hash_info);
return (1);
}
diff --git a/builtins/help.def b/builtins/help.def
index 35a6de9..f857af9 100644
--- a/builtins/help.def
+++ b/builtins/help.def
@@ -1,35 +1,46 @@
This file is help.def, from which is created help.c.
It implements the builtin "help" in Bash.
-Copyright (C) 1987-2003 Free Software Foundation, Inc.
+Copyright (C) 1987-2009 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 2, or (at your option) any later
-version.
+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.
+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; see the file COPYING. If not, write to the Free Software
-Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
+You should have received a copy of the GNU General Public License
+along with Bash. If not, see <http://www.gnu.org/licenses/>.
$PRODUCES help.c
$BUILTIN help
$FUNCTION help_builtin
$DEPENDS_ON HELP_BUILTIN
-$SHORT_DOC help [-s] [pattern ...]
-Display helpful information about builtin commands. If PATTERN is
+$SHORT_DOC help [-dms] [pattern ...]
+Display information about builtin commands.
+
+Displays brief summaries of builtin commands. If PATTERN is
specified, gives detailed help on all commands matching PATTERN,
-otherwise a list of the builtins is printed. The -s option
-restricts the output for each builtin command matching PATTERN to
-a short usage synopsis.
+otherwise the list of help topics is printed.
+
+Options:
+ -d output short description for each topic
+ -m display usage in pseudo-manpage format
+ -s output only a short usage synopsis for each topic matching
+ PATTERN
+
+Arguments:
+ PATTERN Pattern specifiying a help topic
+
+Exit Status:
+Returns success unless PATTERN is not found or an invalid option is given.
$END
#include <config.h>
@@ -63,7 +74,13 @@ $END
extern int errno;
#endif
+extern const char * const bash_copyright;
+extern const char * const bash_license;
+
static void show_builtin_command_help __P((void));
+static int open_helpfile __P((char *));
+static void show_desc __P((char *, int));
+static void show_manpage __P((char *, int));
static void show_longdoc __P((int));
/* Print out a list of the known functions in the shell, and what they do.
@@ -75,14 +92,20 @@ help_builtin (list)
{
register int i;
char *pattern, *name;
- int plen, match_found, sflag;
+ int plen, match_found, sflag, dflag, mflag;
- sflag = 0;
+ dflag = sflag = mflag = 0;
reset_internal_getopt ();
- while ((i = internal_getopt (list, "s")) != -1)
+ while ((i = internal_getopt (list, "dms")) != -1)
{
switch (i)
{
+ case 'd':
+ dflag = 1;
+ break;
+ case 'm':
+ mflag = 1;
+ break;
case 's':
sflag = 1;
break;
@@ -104,10 +127,7 @@ help_builtin (list)
if (glob_pattern_p (list->word->word))
{
- if (list->next)
- printf (_("Shell commands matching keywords `"));
- else
- printf (_("Shell commands matching keyword `"));
+ printf (ngettext ("Shell commands matching keyword `", "Shell commands matching keywords `", (list->next ? 2 : 1)));
print_word_list (list, ", ");
printf ("'\n\n");
}
@@ -123,12 +143,22 @@ help_builtin (list)
if ((strncmp (pattern, name, plen) == 0) ||
(strmatch (pattern, name, FNMATCH_EXTFLAG) != FNM_NOMATCH))
{
+ match_found++;
+ if (dflag)
+ {
+ show_desc (name, i);
+ continue;
+ }
+ else if (mflag)
+ {
+ show_manpage (name, i);
+ continue;
+ }
+
printf ("%s: %s\n", name, shell_builtins[i].short_doc);
if (sflag == 0)
show_longdoc (i);
-
- match_found++;
}
}
}
@@ -143,6 +173,21 @@ help_builtin (list)
return (EXECUTION_SUCCESS);
}
+static int
+open_helpfile (name)
+ char *name;
+{
+ int fd;
+
+ fd = open (name, O_RDONLY);
+ if (fd == -1)
+ {
+ builtin_error (_("%s: cannot open: %s"), name, strerror (errno));
+ return -1;
+ }
+ return fd;
+}
+
/* By convention, enforced by mkbuiltins.c, if separate help files are being
used, the long_doc array contains one string -- the full pathname of the
help file for this builtin. */
@@ -158,12 +203,9 @@ show_longdoc (i)
if (doc && doc[0] && *doc[0] == '/' && doc[1] == (char *)NULL)
{
- fd = open (doc[0], O_RDONLY);
- if (fd == -1)
- {
- builtin_error (_("%s: cannot open: %s"), doc[0], strerror (errno));
- return;
- }
+ fd = open_helpfile (doc[0]);
+ if (fd < 0)
+ return;
zcatfd (fd, 1, doc[0]);
close (fd);
}
@@ -173,10 +215,123 @@ show_longdoc (i)
}
static void
+show_desc (name, i)
+ char *name;
+ int i;
+{
+ register int j;
+ char **doc, *line;
+ int fd, usefile;
+
+ doc = (char **)shell_builtins[i].long_doc;
+
+ usefile = (doc && doc[0] && *doc[0] == '/' && doc[1] == (char *)NULL);
+ if (usefile)
+ {
+ fd = open_helpfile (doc[0]);
+ if (fd < 0)
+ return;
+ zmapfd (fd, &line, doc[0]);
+ close (fd);
+ }
+ else
+ line = doc ? doc[0] : (char *)NULL;
+
+ printf ("%s - ", name);
+ for (j = 0; line && line[j]; j++)
+ {
+ putchar (line[j]);
+ if (line[j] == '\n')
+ break;
+ }
+
+ fflush (stdout);
+
+ if (usefile)
+ free (line);
+}
+
+/* Print builtin help in pseudo-manpage format. */
+static void
+show_manpage (name, i)
+ char *name;
+ int i;
+{
+ register int j;
+ char **doc, *line;
+ int fd, usefile;
+
+ doc = (char **)shell_builtins[i].long_doc;
+
+ usefile = (doc && doc[0] && *doc[0] == '/' && doc[1] == (char *)NULL);
+ if (usefile)
+ {
+ fd = open_helpfile (doc[0]);
+ if (fd < 0)
+ return;
+ zmapfd (fd, &line, doc[0]);
+ close (fd);
+ }
+ else
+ line = doc ? _(doc[0]) : (char *)NULL;
+
+ /* NAME */
+ printf ("NAME\n");
+ printf ("%*s%s - ", BASE_INDENT, " ", name);
+ for (j = 0; line && line[j]; j++)
+ {
+ putchar (line[j]);
+ if (line[j] == '\n')
+ break;
+ }
+ printf ("\n");
+
+ /* SYNOPSIS */
+ printf ("SYNOPSIS\n");
+ printf ("%*s%s\n\n", BASE_INDENT, " ", shell_builtins[i].short_doc);
+
+ /* DESCRIPTION */
+ printf ("DESCRIPTION\n");
+ if (usefile == 0)
+ {
+ for (j = 0; doc[j]; j++)
+ printf ("%*s%s\n", BASE_INDENT, " ", _(doc[j]));
+ }
+ else
+ {
+ for (j = 0; line && line[j]; j++)
+ {
+ putchar (line[j]);
+ if (line[j] == '\n')
+ printf ("%*s", BASE_INDENT, " ");
+ }
+ }
+ putchar ('\n');
+
+ /* SEE ALSO */
+ printf ("SEE ALSO\n");
+ printf ("%*sbash(1)\n\n", BASE_INDENT, " ");
+
+ /* IMPLEMENTATION */
+ printf ("IMPLEMENTATION\n");
+ printf ("%*s", BASE_INDENT, " ");
+ show_shell_version (0);
+ printf ("%*s", BASE_INDENT, " ");
+ printf ("%s\n", _(bash_copyright));
+ printf ("%*s", BASE_INDENT, " ");
+ printf ("%s\n", _(bash_license));
+
+ fflush (stdout);
+ if (usefile)
+ free (line);
+}
+
+static void
show_builtin_command_help ()
{
int i, j;
- char blurb[36];
+ int height, width;
+ char *t, blurb[128];
printf (
_("These shell commands are defined internally. Type `help' to see this list.\n\
@@ -187,21 +342,44 @@ Use `man -k' or `info' to find out more about commands not in this list.\n\
A star (*) next to a name means that the command is disabled.\n\
\n"));
- for (i = 0; i < num_shell_builtins; i++)
+ t = get_string_value ("COLUMNS");
+ width = (t && *t) ? atoi (t) : 80;
+ if (width <= 0)
+ width = 80;
+
+ width /= 2;
+ if (width > sizeof (blurb))
+ width = sizeof (blurb);
+ if (width <= 3)
+ width = 40;
+ height = (num_shell_builtins + 1) / 2; /* number of rows */
+
+ for (i = 0; i < height; i++)
{
QUIT;
+
+ /* first column */
blurb[0] = (shell_builtins[i].flags & BUILTIN_ENABLED) ? ' ' : '*';
- strncpy (blurb + 1, shell_builtins[i].short_doc, 34);
- blurb[35] = '\0';
+ strncpy (blurb + 1, shell_builtins[i].short_doc, width - 2);
+ blurb[width - 2] = '>'; /* indicate truncation */
+ blurb[width - 1] = '\0';
printf ("%s", blurb);
+ if (((i << 1) >= num_shell_builtins) || (i+height >= num_shell_builtins))
+ {
+ printf ("\n");
+ break;
+ }
+
+ /* two spaces */
+ for (j = strlen (blurb); j < width; j++)
+ putc (' ', stdout);
- if (i % 2)
- printf ("\n");
- else
- for (j = strlen (blurb); j < 35; j++)
- putc (' ', stdout);
+ /* second column */
+ blurb[0] = (shell_builtins[i+height].flags & BUILTIN_ENABLED) ? ' ' : '*';
+ strncpy (blurb + 1, shell_builtins[i+height].short_doc, width - 3);
+ blurb[width - 3] = '>'; /* indicate truncation */
+ blurb[width - 2] = '\0';
+ printf ("%s\n", blurb);
}
- if (i % 2)
- printf ("\n");
}
#endif /* HELP_BUILTIN */
diff --git a/builtins/history.def b/builtins/history.def
index efee005..e8249e9 100644
--- a/builtins/history.def
+++ b/builtins/history.def
@@ -1,51 +1,58 @@
This file is history.def, from which is created history.c.
It implements the builtin "history" in Bash.
-Copyright (C) 1987-2003 Free Software Foundation, Inc.
+Copyright (C) 1987-2009 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 2, or (at your option) any later
-version.
+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.
+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; see the file COPYING. If not, write to the Free Software
-Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
+You should have received a copy of the GNU General Public License
+along with Bash. If not, see <http://www.gnu.org/licenses/>.
$PRODUCES history.c
$BUILTIN history
$FUNCTION history_builtin
$DEPENDS_ON HISTORY
-$SHORT_DOC history [-c] [-d offset] [n] or history -awrn [filename] or history -ps arg [arg...]
-Display the history list with line numbers. Lines listed with
-with a `*' have been modified. Argument of N says to list only
-the last N lines. The `-c' option causes the history list to be
-cleared by deleting all of the entries. The `-d' option deletes
-the history entry at offset OFFSET. The `-w' option writes out the
-current history to the history file; `-r' means to read the file and
-append the contents to the history list instead. `-a' means
-to append history lines from this session to the history file.
-Argument `-n' means to read all history lines not already read
-from the history file and append them to the history list.
-
-If FILENAME is given, then that is used as the history file else
+$SHORT_DOC history [-c] [-d offset] [n] or history -anrw [filename] or history -ps arg [arg...]
+Display or manipulate the history list.
+
+Display the history list with line numbers, prefixing each modified
+entry with a `*'. An argument of N lists only the last N entries.
+
+Options:
+ -c clear the history list by deleting all of the entries
+ -d offset delete the history entry at offset OFFSET.
+
+ -a append history lines from this session to the history file
+ -n read all history lines not already read from the history file
+ -r read the history file and append the contents to the history
+ list
+ -w write the current history to the history file
+ and append them to the history list
+
+ -p perform history expansion on each ARG and display the result
+ without storing it in the history list
+ -s append the ARGs to the history list as a single entry
+
+If FILENAME is given, it is used as the history file. Otherwise,
if $HISTFILE has a value, that is used, else ~/.bash_history.
-If the -s option is supplied, the non-option ARGs are appended to
-the history list as a single entry. The -p option means to perform
-history expansion on each ARG and display the result, without storing
-anything in the history list.
If the $HISTTIMEFORMAT variable is set and not null, its value is used
as a format string for strftime(3) to print the time stamp associated
with each displayed history entry. No time stamps are printed otherwise.
+
+Exit Status:
+Returns success unless an invalid option is given or an error occurs.
$END
#include <config.h>
@@ -79,11 +86,8 @@ extern int errno;
extern int current_command_line_count;
extern int force_append_history; /* shopt -s histappend */
-int delete_last_history __P((void));
-
static char *histtime __P((HIST_ENTRY *, const char *));
-static void display_history __P((WORD_LIST *));
-static int delete_histent __P((int));
+static int display_history __P((WORD_LIST *));
static void push_history __P((WORD_LIST *));
static int expand_and_print_history __P((WORD_LIST *));
@@ -154,7 +158,7 @@ history_builtin (list)
/* clear the history, but allow other arguments to add to it again. */
if (flags & CFLAG)
{
- clear_history ();
+ bash_clear_history ();
if (list == 0)
return (EXECUTION_SUCCESS);
}
@@ -170,7 +174,7 @@ history_builtin (list)
{
if (list)
return (expand_and_print_history (list));
- return (EXECUTION_SUCCESS);
+ return (sh_chkwrite (EXECUTION_SUCCESS));
}
#endif
else if (flags & DFLAG)
@@ -183,7 +187,7 @@ history_builtin (list)
return (EXECUTION_FAILURE);
}
opt = delete_offset;
- result = delete_histent (opt - history_base);
+ result = bash_delete_histent (opt - history_base);
/* Since remove_history changes history_length, this can happen if
we delete the last history entry. */
if (where_history () > history_length)
@@ -192,8 +196,8 @@ history_builtin (list)
}
else if ((flags & (AFLAG|RFLAG|NFLAG|WFLAG|CFLAG)) == 0)
{
- display_history (list);
- return (EXECUTION_SUCCESS);
+ result = display_history (list);
+ return (sh_chkwrite (result));
}
filename = list ? list->word->word : get_string_value ("HISTFILE");
@@ -255,7 +259,7 @@ histtime (hlist, histtimefmt)
return timestr;
}
-static void
+static int
display_history (list)
WORD_LIST *list;
{
@@ -266,7 +270,9 @@ display_history (list)
if (list)
{
- limit = get_numeric_arg (list, 0);
+ if (get_numeric_arg (list, 0, &limit) == 0)
+ return (EXECUTION_FAILURE);
+
if (limit < 0)
limit = -limit;
}
@@ -285,7 +291,6 @@ display_history (list)
else
i = 0;
-
histtimefmt = get_string_value ("HISTTIMEFORMAT");
while (hlist[i])
@@ -300,48 +305,8 @@ display_history (list)
i++;
}
}
-}
-
-/* Delete and free the history list entry at offset I. */
-static int
-delete_histent (i)
- int i;
-{
- HIST_ENTRY *discard;
-
- discard = remove_history (i);
- if (discard)
- free_history_entry (discard);
-
- return 1;
-}
-
-int
-delete_last_history ()
-{
- register int i;
- HIST_ENTRY **hlist, *histent;
- int r;
-
- hlist = history_list ();
- if (hlist == NULL)
- return 0;
-
- for (i = 0; hlist[i]; i++)
- ;
- i--;
-
- /* History_get () takes a parameter that must be offset by history_base. */
- histent = history_get (history_base + i); /* Don't free this */
- if (histent == NULL)
- return 0;
-
- r = delete_histent (i);
-
- if (where_history () > history_length)
- history_set_pos (history_length);
- return r;
+ return (EXECUTION_SUCCESS);
}
/* Remove the last entry in the history list and add each argument in
@@ -359,12 +324,12 @@ push_history (list)
If you don't want history -s to remove the compound command from the
history, change #if 0 to #if 1 below. */
#if 0
- if (hist_last_line_pushed == 0 && hist_last_line_added && delete_last_history () == 0)
+ if (hist_last_line_pushed == 0 && hist_last_line_added && bash_delete_last_history () == 0)
#else
if (hist_last_line_pushed == 0 &&
(hist_last_line_added ||
(current_command_line_count > 0 && current_command_first_line_saved && command_oriented_history))
- && delete_last_history () == 0)
+ && bash_delete_last_history () == 0)
#endif
return;
@@ -389,7 +354,7 @@ expand_and_print_history (list)
char *s;
int r, result;
- if (hist_last_line_pushed == 0 && hist_last_line_added && delete_last_history () == 0)
+ if (hist_last_line_pushed == 0 && hist_last_line_added && bash_delete_last_history () == 0)
return EXECUTION_FAILURE;
result = EXECUTION_SUCCESS;
while (list)
diff --git a/builtins/inlib.def b/builtins/inlib.def
index 094c4b9..c4faf0d 100644
--- a/builtins/inlib.def
+++ b/builtins/inlib.def
@@ -5,19 +5,18 @@ Copyright (C) 1987-2002 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 2, or (at your option) any later
-version.
+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.
+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; see the file COPYING. If not, write to the Free Software
-Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
+You should have received a copy of the GNU General Public License
+along with Bash. If not, see <http://www.gnu.org/licenses/>.
$PRODUCES inlib.c
#include <config.h>
@@ -29,12 +28,17 @@ $BUILTIN inlib
$FUNCTION inlib_builtin
$DEPENDS_ON apollo
$SHORT_DOC inlib pathname [pathname...]
+Install user-supplied library.
+
Install a user-supplied library specified by pathname in the current
shell process. The library is used to resolve external references
in programs and libraries loaded after its installation. Note
that the library is not loaded into the address space unless it is
needed to resolve an external reference. The list of inlibed
libraries is passed to all children of the current shell.
+
+Exit Status:
+Returns success unless PATHNAME is not found or an error occurs.
$END
#if defined (apollo)
@@ -64,7 +68,7 @@ inlib_builtin (list)
if (status.all != status_$ok)
{
- builtin_error ("%s: inlib failed", list->word->word);
+ builtin_error (_("%s: inlib failed"), list->word->word);
return_value = EXECUTION_FAILURE;
}
diff --git a/builtins/jobs.def b/builtins/jobs.def
index 4c3ba6a..b14e91f 100644
--- a/builtins/jobs.def
+++ b/builtins/jobs.def
@@ -1,23 +1,22 @@
This file is jobs.def, from which is created jobs.c.
It implements the builtins "jobs" and "disown" in Bash.
-Copyright (C) 1987-2005 Free Software Foundation, Inc.
+Copyright (C) 1987-2009 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 2, or (at your option) any later
-version.
+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.
+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; see the file COPYING. If not, write to the Free Software
-Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
+You should have received a copy of the GNU General Public License
+along with Bash. If not, see <http://www.gnu.org/licenses/>.
$PRODUCES jobs.c
@@ -25,15 +24,26 @@ $BUILTIN jobs
$FUNCTION jobs_builtin
$DEPENDS_ON JOB_CONTROL
$SHORT_DOC jobs [-lnprs] [jobspec ...] or jobs -x command [args]
-Lists the active jobs. The -l option lists process id's in addition
-to the normal information; the -p option lists process id's only.
-If -n is given, only processes that have changed status since the last
-notification are printed. JOBSPEC restricts output to that job. The
--r and -s options restrict output to running and stopped jobs only,
-respectively. Without options, the status of all active jobs is
-printed. If -x is given, COMMAND is run after all job specifications
-that appear in ARGS have been replaced with the process ID of that job's
+Display status of jobs.
+
+Lists the active jobs. JOBSPEC restricts output to that job.
+Without options, the status of all active jobs is displayed.
+
+Options:
+ -l lists process IDs in addition to the normal information
+ -n list only processes that have changed status since the last
+ notification
+ -p lists process IDs only
+ -r restrict output to running jobs
+ -s restrict output to stopped jobs
+
+If -x is supplied, COMMAND is run after all job specifications that
+appear in ARGS have been replaced with the process ID of that job's
process group leader.
+
+Exit Status:
+Returns success unless an invalid option is given or an error occurs.
+If -x is used, returns the exit status of COMMAND.
$END
#include <config.h>
@@ -203,11 +213,19 @@ $BUILTIN disown
$FUNCTION disown_builtin
$DEPENDS_ON JOB_CONTROL
$SHORT_DOC disown [-h] [-ar] [jobspec ...]
-By default, removes each JOBSPEC argument from the table of active jobs.
-If the -h option is given, the job is not removed from the table, but is
-marked so that SIGHUP is not sent to the job if the shell receives a
-SIGHUP. The -a option, when JOBSPEC is not supplied, means to remove all
-jobs from the job table; the -r option means to remove only running jobs.
+Remove jobs from current shell.
+
+Removes each JOBSPEC argument from the table of active jobs. Without
+any JOBSPECs, the shell uses its notion of the current job.
+
+Options:
+ -a remove all jobs if JOBSPEC is not supplied
+ -h mark each JOBSPEC so that SIGHUP is not sent to the job if the
+ shell receives a SIGHUP
+ -r remove only running jobs
+
+Exit Status:
+Returns success unless an invalid option or JOBSPEC is given.
$END
#if defined (JOB_CONTROL)
@@ -261,7 +279,7 @@ disown_builtin (list)
if (job == NO_JOB || jobs == 0 || INVALID_JOB (job))
{
- sh_badjob (list ? list->word->word : "current");
+ sh_badjob (list ? list->word->word : _("current"));
retval = EXECUTION_FAILURE;
}
else if (nohup_only)
diff --git a/builtins/kill.def b/builtins/kill.def
index bedbb1a..18c3667 100644
--- a/builtins/kill.def
+++ b/builtins/kill.def
@@ -1,36 +1,46 @@
This file is kill.def, from which is created kill.c.
It implements the builtin "kill" in Bash.
-Copyright (C) 1987-2005 Free Software Foundation, Inc.
+Copyright (C) 1987-2009 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 2, or (at your option) any later
-version.
+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.
+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; see the file COPYING. If not, write to the Free Software
-Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
+You should have received a copy of the GNU General Public License
+along with Bash. If not, see <http://www.gnu.org/licenses/>.
$PRODUCES kill.c
$BUILTIN kill
$FUNCTION kill_builtin
$SHORT_DOC kill [-s sigspec | -n signum | -sigspec] pid | jobspec ... or kill -l [sigspec]
-Send the processes named by PID (or JOBSPEC) the signal SIGSPEC. If
-SIGSPEC is not present, then SIGTERM is assumed. An argument of `-l'
-lists the signal names; if arguments follow `-l' they are assumed to
-be signal numbers for which names should be listed. Kill is a shell
-builtin for two reasons: it allows job IDs to be used instead of
-process IDs, and, if you have reached the limit on processes that
-you can create, you don't have to start a process to kill another one.
+Send a signal to a job.
+
+Send the processes identified by PID or JOBSPEC the signal named by
+SIGSPEC or SIGNUM. If neither SIGSPEC nor SIGNUM is present, then
+SIGTERM is assumed.
+
+Options:
+ -s sig SIG is a signal name
+ -n sig SIG is a signal number
+ -l list the signal names; if arguments follow `-l' they are
+ assumed to be signal numbers for which names should be listed
+
+Kill is a shell builtin for two reasons: it allows job IDs to be used
+instead of process IDs, and allows processes to be killed if the limit
+on processes that you can create is reached.
+
+Exit Status:
+Returns success unless an invalid option is given or an error occurs.
$END
#include <config.h>
@@ -111,6 +121,9 @@ kill_builtin (list)
else
sig = decode_signal (sigspec, dflags);
list = list->next;
+#if 0
+ saw_signal++; /* XXX - for bash-4.2 */
+#endif
}
else
{
@@ -131,7 +144,7 @@ kill_builtin (list)
/* If this is a signal specification then process it. We only process
the first one seen; other arguments may signify process groups (e.g,
-num == process group num). */
- else if ((*word == '-') && !saw_signal)
+ else if (*word == '-' && saw_signal == 0)
{
sigspec = word + 1;
sig = decode_signal (sigspec, dflags);
diff --git a/builtins/let.def b/builtins/let.def
index ab43a45..2601fb9 100644
--- a/builtins/let.def
+++ b/builtins/let.def
@@ -1,33 +1,34 @@
This file is let.def, from which is created let.c.
It implements the builtin "let" in Bash.
-Copyright (C) 1987-2002 Free Software Foundation, Inc.
+Copyright (C) 1987-2009 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 2, or (at your option) any later
-version.
+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.
+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; see the file COPYING. If not, write to the Free Software
-Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
+You should have received a copy of the GNU General Public License
+along with Bash. If not, see <http://www.gnu.org/licenses/>.
$BUILTIN let
$FUNCTION let_builtin
$PRODUCES let.c
$SHORT_DOC let arg [arg ...]
-Each ARG is an arithmetic expression to be evaluated. Evaluation
-is done in fixed-width integers with no check for overflow, though
-division by 0 is trapped and flagged as an error. The following
-list of operators is grouped into levels of equal-precedence operators.
-The levels are listed in order of decreasing precedence.
+Evaluate arithmetic expressions.
+
+Evaluate each ARG as an arithmetic expression. Evaluation is done in
+fixed-width integers with no check for overflow, though division by 0
+is trapped and flagged as an error. The following list of operators is
+grouped into levels of equal-precedence operators. The levels are listed
+in order of decreasing precedence.
id++, id-- variable post-increment, post-decrement
++id, --id variable pre-increment, pre-decrement
@@ -59,8 +60,8 @@ Operators are evaluated in order of precedence. Sub-expressions in
parentheses are evaluated first and may override the precedence
rules above.
-If the last ARG evaluates to 0, let returns 1; 0 is returned
-otherwise.
+Exit Status:
+If the last ARG evaluates to 0, let returns 1; let returns 0 otherwise..
$END
#include <config.h>
diff --git a/builtins/mapfile.def b/builtins/mapfile.def
new file mode 100644
index 0000000..0946de3
--- /dev/null
+++ b/builtins/mapfile.def
@@ -0,0 +1,351 @@
+This file is mapfile.def, from which is created mapfile.c.
+It implements the builtin "mapfile" in Bash.
+
+Copyright (C) 2005-2006 Rocky Bernstein for Free Software Foundation, Inc.
+Copyright (C) 2008,2009 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 mapfile.c
+
+$BUILTIN mapfile
+$FUNCTION mapfile_builtin
+$SHORT_DOC mapfile [-n count] [-O origin] [-s count] [-t] [-u fd] [-C callback] [-c quantum] [array]
+Read lines from the standard input into an indexed array variable.
+
+Read lines from the standard input into the indexed array variable ARRAY, or
+from file descriptor FD if the -u option is supplied. The variable MAPFILE
+is the default ARRAY.
+
+Options:
+ -n count Copy at most COUNT lines. If COUNT is 0, all lines are copied.
+ -O origin Begin assigning to ARRAY at index ORIGIN. The default index is 0.
+ -s count Discard the first COUNT lines read.
+ -t Remove a trailing newline from each line read.
+ -u fd Read lines from file descriptor FD instead of the standard input.
+ -C callback Evaluate CALLBACK each time QUANTUM lines are read.
+ -c quantum Specify the number of lines read between each call to CALLBACK.
+
+Arguments:
+ ARRAY Array variable name to use for file data.
+
+If -C is supplied without -c, the default quantum is 5000. When
+CALLBACK is evaluated, it is supplied the index of the next array
+element to be assigned as an additional argument.
+
+If not supplied with an explicit origin, mapfile will clear ARRAY before
+assigning to it.
+
+Exit Status:
+Returns success unless an invalid option is given or ARRAY is readonly or
+not an indexed array.
+$END
+
+$BUILTIN readarray
+$FUNCTION mapfile_builtin
+$SHORT_DOC readarray [-n count] [-O origin] [-s count] [-t] [-u fd] [-C callback] [-c quantum] [array]
+Read lines from a file into an array variable.
+
+A synonym for `mapfile'.
+$END
+
+#include <config.h>
+
+#include "builtins.h"
+#include "posixstat.h"
+
+#if defined (HAVE_UNISTD_H)
+# include <unistd.h>
+#endif
+
+#include "bashansi.h"
+#include "bashintl.h"
+
+#include <stdio.h>
+#include <errno.h>
+
+#include "../bashintl.h"
+#include "../shell.h"
+#include "common.h"
+#include "bashgetopt.h"
+
+#if !defined (errno)
+extern int errno;
+#endif
+
+#if defined (ARRAY_VARS)
+
+#define DEFAULT_ARRAY_NAME "MAPFILE"
+
+/* The value specifying how frequently `mapfile' calls the callback. */
+#define DEFAULT_QUANTUM 5000
+
+/* Values for FLAGS */
+#define MAPF_CLEARARRAY 0x01
+#define MAPF_CHOP 0x02
+
+static int
+run_callback(callback, current_index)
+ const char *callback;
+ unsigned int current_index;
+{
+ unsigned int execlen;
+ char *execstr;
+ int flags;
+
+ execlen = strlen (callback) + 10;
+ /* 1 for space between %s and %d,
+ another 1 for the last nul char for C string. */
+ execlen += 2;
+ execstr = xmalloc (execlen);
+
+ flags = SEVAL_NOHIST;
+#if 0
+ if (interactive)
+ flags |= SEVAL_INTERACT;
+#endif
+ snprintf (execstr, execlen, "%s %d", callback, current_index);
+ return parse_and_execute(execstr, NULL, flags);
+}
+
+static void
+do_chop(line)
+ char * line;
+{
+ int length;
+
+ length = strlen (line);
+ if (length && line[length-1] == '\n')
+ line[length-1] = '\0';
+}
+
+static int
+mapfile (fd, line_count_goal, origin, nskip, callback_quantum, callback, array_name, flags)
+ int fd;
+ long line_count_goal, origin, nskip, callback_quantum;
+ char *callback, *array_name;
+ int flags;
+{
+ char *line;
+ size_t line_length;
+ unsigned int array_index, line_count;
+ SHELL_VAR *entry;
+ int unbuffered_read;
+
+ line = NULL;
+ line_length = 0;
+ unbuffered_read = 0;
+
+ /* The following check should be done before reading any lines. Doing it
+ here allows us to call bind_array_element instead of bind_array_variable
+ and skip the variable lookup on every call. */
+ entry = find_or_make_array_variable (array_name, 1);
+ if (entry == 0 || readonly_p (entry) || noassign_p (entry))
+ {
+ if (entry && readonly_p (entry))
+ err_readonly (array_name);
+
+ return (EXECUTION_FAILURE);
+ }
+ else if (array_p (entry) == 0)
+ {
+ builtin_error (_("%s: not an indexed array"), array_name);
+ return (EXECUTION_FAILURE);
+ }
+
+ if (flags & MAPF_CLEARARRAY)
+ array_flush (array_cell (entry));
+
+#ifndef __CYGWIN__
+ unbuffered_read = (lseek (fd, 0L, SEEK_CUR) < 0) && (errno == ESPIPE);
+#else
+ unbuffered_read = 1;
+#endif
+
+ zreset ();
+
+ /* Skip any lines at beginning of file? */
+ for (line_count = 0; line_count < nskip; line_count++)
+ if (zgetline (fd, &line, &line_length, unbuffered_read) < 0)
+ break;
+
+ line = 0;
+ line_length = 0;
+
+ /* Reset the buffer for bash own stream */
+ interrupt_immediately++;
+ for (array_index = origin, line_count = 1;
+ zgetline (fd, &line, &line_length, unbuffered_read) != -1;
+ array_index++, line_count++)
+ {
+ /* Have we exceeded # of lines to store? */
+ if (line_count_goal != 0 && line_count > line_count_goal)
+ break;
+
+ /* Remove trailing newlines? */
+ if (flags & MAPF_CHOP)
+ do_chop (line);
+
+ /* Has a callback been registered and if so is it time to call it? */
+ if (callback && line_count && (line_count % callback_quantum) == 0)
+ {
+ run_callback (callback, array_index);
+
+ /* Reset the buffer for bash own stream. */
+ if (unbuffered_read == 0)
+ zsyncfd (fd);
+ }
+
+ bind_array_element (entry, array_index, line, 0);
+ }
+
+ xfree (line);
+
+ if (unbuffered_read == 0)
+ zsyncfd (fd);
+
+ interrupt_immediately--;
+ return EXECUTION_SUCCESS;
+}
+
+int
+mapfile_builtin (list)
+ WORD_LIST *list;
+{
+ int opt, code, fd, clear_array, flags;
+ intmax_t intval;
+ long lines, origin, nskip, callback_quantum;
+ char *array_name, *callback;
+
+ clear_array = 1;
+ fd = 0;
+ lines = origin = nskip = 0;
+ flags = MAPF_CLEARARRAY;
+ callback_quantum = DEFAULT_QUANTUM;
+ callback = 0;
+
+ reset_internal_getopt ();
+ while ((opt = internal_getopt (list, "u:n:O:tC:c:s:")) != -1)
+ {
+ switch (opt)
+ {
+ case 'u':
+ code = legal_number (list_optarg, &intval);
+ if (code == 0 || intval < 0 || intval != (int)intval)
+ {
+ builtin_error (_("%s: invalid file descriptor specification"), list_optarg);
+ return (EXECUTION_FAILURE);
+ }
+ else
+ fd = intval;
+
+ if (sh_validfd (fd) == 0)
+ {
+ builtin_error (_("%d: invalid file descriptor: %s"), fd, strerror (errno));
+ return (EXECUTION_FAILURE);
+ }
+ break;
+
+ case 'n':
+ code = legal_number (list_optarg, &intval);
+ if (code == 0 || intval < 0 || intval != (unsigned)intval)
+ {
+ builtin_error (_("%s: invalid line count"), list_optarg);
+ return (EXECUTION_FAILURE);
+ }
+ else
+ lines = intval;
+ break;
+
+ case 'O':
+ code = legal_number (list_optarg, &intval);
+ if (code == 0 || intval < 0 || intval != (unsigned)intval)
+ {
+ builtin_error (_("%s: invalid array origin"), list_optarg);
+ return (EXECUTION_FAILURE);
+ }
+ else
+ origin = intval;
+ flags &= ~MAPF_CLEARARRAY;
+ break;
+ case 't':
+ flags |= MAPF_CHOP;
+ break;
+ case 'C':
+ callback = list_optarg;
+ break;
+ case 'c':
+ code = legal_number (list_optarg, &intval);
+ if (code == 0 || intval <= 0 || intval != (unsigned)intval)
+ {
+ builtin_error (_("%s: invalid callback quantum"), list_optarg);
+ return (EXECUTION_FAILURE);
+ }
+ else
+ callback_quantum = intval;
+ break;
+ case 's':
+ code = legal_number (list_optarg, &intval);
+ if (code == 0 || intval < 0 || intval != (unsigned)intval)
+ {
+ builtin_error (_("%s: invalid line count"), list_optarg);
+ return (EXECUTION_FAILURE);
+ }
+ else
+ nskip = intval;
+ break;
+ default:
+ builtin_usage ();
+ return (EX_USAGE);
+ }
+ }
+ list = loptend;
+
+ if (list == 0)
+ array_name = DEFAULT_ARRAY_NAME;
+ else if (list->word == 0 || list->word->word == 0)
+ {
+ builtin_error ("internal error: getting variable name");
+ return (EXECUTION_FAILURE);
+ }
+ else if (list->word->word[0] == '\0')
+ {
+ builtin_error (_("empty array variable name"));
+ return (EX_USAGE);
+ }
+ else
+ array_name = list->word->word;
+
+ if (legal_identifier (array_name) == 0 && valid_array_reference (array_name) == 0)
+ {
+ sh_invalidid (array_name);
+ return (EXECUTION_FAILURE);
+ }
+
+ return mapfile (fd, lines, origin, nskip, callback_quantum, callback, array_name, flags);
+}
+
+#else
+
+int
+mapfile_builtin (list)
+ WORD_LIST *list;
+{
+ builtin_error (_("array variable support required"));
+ return (EXECUTION_FAILURE);
+}
+
+#endif /* ARRAY_VARS */
diff --git a/builtins/mkbuiltins.c b/builtins/mkbuiltins.c
index ff0bdc0..cdd45e4 100644
--- a/builtins/mkbuiltins.c
+++ b/builtins/mkbuiltins.c
@@ -1,23 +1,23 @@
/* mkbuiltins.c - Create builtins.c, builtext.h, and builtdoc.c from
a single source file called builtins.def. */
-/* Copyright (C) 1987-2006 Free Software Foundation, Inc.
+/* Copyright (C) 1987-2009 Free Software Foundation, Inc.
-This file is part of GNU Bash, the Bourne Again SHell.
+ 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 2, or (at your option) any later
-version.
+ 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.
+ 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; see the file COPYING. If not, write to the Free Software
-Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
+ You should have received a copy of the GNU General Public License
+ along with Bash. If not, see <http://www.gnu.org/licenses/>.
+*/
#if !defined (CROSS_COMPILING)
# include <config.h>
@@ -71,6 +71,7 @@ extern char *strcpy ();
/* Flag values that builtins can have. */
#define BUILTIN_FLAG_SPECIAL 0x01
#define BUILTIN_FLAG_ASSIGNMENT 0x02
+#define BUILTIN_FLAG_POSIX_BUILTIN 0x04
#define BASE_INDENT 4
@@ -154,9 +155,18 @@ char *assignment_builtins[] =
(char *)NULL
};
+/* The builtin commands that are special to the POSIX search order. */
+char *posix_builtins[] =
+{
+ "alias", "bg", "cd", "command", "false", "fc", "fg", "getopts", "jobs",
+ "kill", "newgrp", "pwd", "read", "true", "umask", "unalias", "wait",
+ (char *)NULL
+};
+
/* Forward declarations. */
static int is_special_builtin ();
static int is_assignment_builtin ();
+static int is_posix_builtin ();
#if !defined (HAVE_RENAME)
static int rename ();
@@ -800,6 +810,8 @@ builtin_handler (self, defs, arg)
new->flags |= BUILTIN_FLAG_SPECIAL;
if (is_assignment_builtin (name))
new->flags |= BUILTIN_FLAG_ASSIGNMENT;
+ if (is_posix_builtin (name))
+ new->flags |= BUILTIN_FLAG_POSIX_BUILTIN;
array_add ((char *)new, defs->builtins);
building_builtin = 1;
@@ -1080,23 +1092,23 @@ char *structfile_header[] = {
"/* This file is manufactured by ./mkbuiltins, and should not be",
" edited by hand. See the source to mkbuiltins for details. */",
"",
- "/* Copyright (C) 1987-2002 Free Software Foundation, Inc.",
+ "/* Copyright (C) 1987-2009 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 2, or (at your option)",
- " any later version.",
+ " 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.",
+ " 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; see the file COPYING. If not, write to the Free",
- " Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */",
+ " along with Bash. If not, see <http://www.gnu.org/licenses/>.",
+ "*/",
"",
"/* The list of shell builtins. Each element is name, function, flags,",
" long-doc, short-doc. The long-doc field contains a pointer to an array",
@@ -1217,14 +1229,15 @@ write_builtins (defs, structfile, externfile)
else
fprintf (structfile, "(sh_builtin_func_t *)0x0, ");
- fprintf (structfile, "%s%s%s, %s_doc,\n",
+ fprintf (structfile, "%s%s%s%s, %s_doc,\n",
"BUILTIN_ENABLED | STATIC_BUILTIN",
(builtin->flags & BUILTIN_FLAG_SPECIAL) ? " | SPECIAL_BUILTIN" : "",
(builtin->flags & BUILTIN_FLAG_ASSIGNMENT) ? " | ASSIGNMENT_BUILTIN" : "",
+ (builtin->flags & BUILTIN_FLAG_POSIX_BUILTIN) ? " | POSIX_BUILTIN" : "",
document_name (builtin));
fprintf
- (structfile, " \"%s\", (char *)NULL },\n",
+ (structfile, " N_(\"%s\"), (char *)NULL },\n",
builtin->shortdoc ? builtin->shortdoc : builtin->name);
}
@@ -1561,6 +1574,13 @@ is_assignment_builtin (name)
return (_find_in_table (name, assignment_builtins));
}
+static int
+is_posix_builtin (name)
+ char *name;
+{
+ return (_find_in_table (name, posix_builtins));
+}
+
#if !defined (HAVE_RENAME)
static int
rename (from, to)
diff --git a/builtins/printf.def b/builtins/printf.def
index 0e1d4aa..e447633 100644
--- a/builtins/printf.def
+++ b/builtins/printf.def
@@ -1,39 +1,49 @@
This file is printf.def, from which is created printf.c.
It implements the builtin "printf" in Bash.
-Copyright (C) 1997-2005 Free Software Foundation, Inc.
+Copyright (C) 1997-2009 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 2, or (at your option) any later
-version.
+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.
+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; see the file COPYING. If not, write to the Free Software
-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
+You should have received a copy of the GNU General Public License
+along with Bash. If not, see <http://www.gnu.org/licenses/>.
$PRODUCES printf.c
$BUILTIN printf
$FUNCTION printf_builtin
$SHORT_DOC printf [-v var] format [arguments]
-printf formats and prints ARGUMENTS under control of the FORMAT. FORMAT
-is a character string which contains three types of objects: plain
-characters, which are simply copied to standard output, character escape
-sequences which are converted and copied to the standard output, and
+Formats and prints ARGUMENTS under control of the FORMAT.
+
+Options:
+ -v var assign the output to shell variable VAR rather than
+ display it on the standard output
+
+FORMAT is a character string which contains three types of objects: plain
+characters, which are simply copied to standard output; character escape
+sequences, which are converted and copied to the standard output; and
format specifications, each of which causes printing of the next successive
-argument. In addition to the standard printf(1) formats, %b means to
-expand backslash escape sequences in the corresponding argument, and %q
-means to quote the argument in a way that can be reused as shell input.
-If the -v option is supplied, the output is placed into the value of the
-shell variable VAR rather than being sent to the standard output.
+argument.
+
+In addition to the standard format specifications described in printf(1)
+and printf(3), printf interprets:
+
+ %b expand backslash escape sequences in the corresponding argument
+ %q quote the argument in a way that can be reused as shell input
+
+Exit Status:
+Returns success unless an invalid option is given or a write or assignment
+error occurs.
$END
#include <config.h>
@@ -49,6 +59,12 @@ $END
# define INT_MIN (-2147483647-1)
#endif
+#if defined (PREFER_STDARG)
+# include <stdarg.h>
+#else
+# include <varargs.h>
+#endif
+
#include <stdio.h>
#include <chartypes.h>
@@ -60,10 +76,15 @@ $END
#include "../bashintl.h"
#include "../shell.h"
+#include "shmbutil.h"
#include "stdc.h"
#include "bashgetopt.h"
#include "common.h"
+#if defined (PRI_MACROS_BROKEN)
+# undef PRIdMAX
+#endif
+
#if !defined (PRIdMAX)
# if HAVE_LONG_LONG
# define PRIdMAX "lld"
@@ -89,31 +110,22 @@ extern int errno;
#define PF(f, func) \
do { \
- char *b = 0; \
int nw; \
clearerr (stdout); \
if (have_fieldwidth && have_precision) \
- nw = asprintf(&b, f, fieldwidth, precision, func); \
+ nw = vflag ? vbprintf (f, fieldwidth, precision, func) : printf (f, fieldwidth, precision, func); \
else if (have_fieldwidth) \
- nw = asprintf(&b, f, fieldwidth, func); \
+ nw = vflag ? vbprintf (f, fieldwidth, func) : printf (f, fieldwidth, func); \
else if (have_precision) \
- nw = asprintf(&b, f, precision, func); \
+ nw = vflag ? vbprintf (f, precision, func) : printf (f, fieldwidth, func); \
else \
- nw = asprintf(&b, f, func); \
+ nw = vflag ? vbprintf (f, func) : printf (f, func); \
tw += nw; \
- if (b) \
+ if (ferror (stdout)) \
{ \
- if (vflag) \
- (void)vbadd (b, nw); \
- else \
- (void)fputs (b, stdout); \
- if (ferror (stdout)) \
- { \
- sh_wrerror (); \
- clearerr (stdout); \
- return (EXECUTION_FAILURE); \
- } \
- free (b); \
+ sh_wrerror (); \
+ clearerr (stdout); \
+ return (EXECUTION_FAILURE); \
} \
} while (0)
@@ -123,7 +135,7 @@ extern int errno;
{ \
if (vflag) \
{ \
- bind_variable (vname, vbuf, 0); \
+ bind_printf_variable (vname, vbuf, 0); \
stupidly_hack_special_variables (vname); \
} \
if (conv_bufsize > 4096 ) \
@@ -138,9 +150,13 @@ extern int errno;
vbsize = 0; \
vbuf = 0; \
} \
+ else if (vbuf) \
+ vbuf[0] = 0; \
+ terminate_immediately--; \
fflush (stdout); \
if (ferror (stdout)) \
{ \
+ sh_wrerror (); \
clearerr (stdout); \
return (EXECUTION_FAILURE); \
} \
@@ -151,17 +167,27 @@ extern int errno;
#define SKIP1 "#'-+ 0"
#define LENMODS "hjlLtz"
+#if !HAVE_ASPRINTF
+extern int asprintf __P((char **, const char *, ...)) __attribute__((__format__ (printf, 2, 3)));
+#endif
+
+#if !HAVE_VSNPRINTF
+extern int vsnprintf __P((char *, size_t, const char *, ...)) __attribute__((__format__ (printf, 3, 4)));
+#endif
+
static void printf_erange __P((char *));
static int printstr __P((char *, char *, int, int, int));
static int tescape __P((char *, char *, int *));
static char *bexpand __P((char *, int, int *, int *));
static char *vbadd __P((char *, int));
+static int vbprintf __P((const char *, ...)) __attribute__((__format__ (printf, 1, 2)));
static char *mklong __P((char *, char *, size_t));
static int getchr __P((void));
static char *getstr __P((void));
static int getint __P((void));
static intmax_t getintmax __P((void));
static uintmax_t getuintmax __P((void));
+static SHELL_VAR *bind_printf_variable __P((char *, char *, int));
#if defined (HAVE_LONG_DOUBLE) && HAVE_DECL_STRTOLD && !defined(STRTOLD_BROKEN)
typedef long double floatmax_t;
@@ -174,7 +200,7 @@ typedef double floatmax_t;
#endif
static floatmax_t getfloatmax __P((void));
-static int asciicode __P((void));
+static intmax_t asciicode __P((void));
static WORD_LIST *garglist;
static int retval;
@@ -210,10 +236,17 @@ printf_builtin (list)
switch (ch)
{
case 'v':
- if (legal_identifier (vname = list_optarg))
+ vname = list_optarg;
+#if defined (ARRAY_VARS)
+ if (legal_identifier (vname) || valid_array_reference (vname))
+#else
+ if (legal_identifier (vname))
+#endif
{
vflag = 1;
vblen = 0;
+ if (vbuf)
+ vbuf[0] = 0;
}
else
{
@@ -245,6 +278,8 @@ printf_builtin (list)
/* If the format string is empty after preprocessing, return immediately. */
if (format == 0 || *format == 0)
return (EXECUTION_SUCCESS);
+
+ terminate_immediately++;
/* Basic algorithm is to scan the format string for conversion
specifications -- once one is found, find out if the field
@@ -540,7 +575,7 @@ static void
printf_erange (s)
char *s;
{
- builtin_error ("warning: %s: %s", s, strerror(ERANGE));
+ builtin_error (_("warning: %s: %s"), s, strerror(ERANGE));
}
/* We duplicate a lot of what printf(3) does here. */
@@ -563,7 +598,7 @@ printstr (fmt, string, len, fieldwidth, precision)
#else
if (string == 0 || len == 0)
#endif
- return;
+ return 0;
#if 0
s = fmt;
@@ -821,7 +856,7 @@ vbadd (buf, blen)
if (blen == 1)
vbuf[vblen++] = buf[0];
- else
+ else if (blen > 1)
{
FASTCOPY (buf, vbuf + vblen, blen);
vblen += blen;
@@ -836,6 +871,44 @@ vbadd (buf, blen)
return vbuf;
}
+static int
+#if defined (PREFER_STDARG)
+vbprintf (const char *format, ...)
+#else
+vbprintf (format, va_alist)
+ const char *format;
+ va_dcl
+#endif
+{
+ va_list args;
+ size_t nlen;
+ int blen;
+
+ SH_VA_START (args, format);
+ blen = vsnprintf (vbuf + vblen, vbsize - vblen, format, args);
+ va_end (args);
+
+ nlen = vblen + blen + 1;
+ if (nlen >= vbsize)
+ {
+ vbsize = ((nlen + 63) >> 6) << 6;
+ vbuf = (char *)xrealloc (vbuf, vbsize);
+ SH_VA_START (args, format);
+ blen = vsnprintf (vbuf + vblen, vbsize - vblen, format, args);
+ va_end (args);
+ }
+
+ vblen += blen;
+ vbuf[vblen] = '\0';
+
+#ifdef DEBUG
+ if (strlen (vbuf) != vblen)
+ internal_error ("printf:vbadd: vblen (%d) != strlen (vbuf) (%d)", vblen, (int)strlen (vbuf));
+#endif
+
+ return (blen);
+}
+
static char *
mklong (str, modifiers, mlen)
char *str;
@@ -931,7 +1004,9 @@ getintmax ()
shall continue processing any remaining operands and shall write the
value accumulated at the time the error was detected to standard
output.'' Yecch. */
- ret = 0;
+#if 0
+ ret = 0; /* return partially-converted value from strtoimax */
+#endif
conversion_error = 1;
}
else if (errno == ERANGE)
@@ -1000,12 +1075,44 @@ getfloatmax ()
}
/* NO check is needed for garglist here. */
-static int
+static intmax_t
asciicode ()
{
- register int ch;
+ register intmax_t ch;
+#if defined (HANDLE_MULTIBYTE)
+ wchar_t wc;
+ size_t mblength, slen;
+#endif
+ DECLARE_MBSTATE;
+
+#if defined (HANDLE_MULTIBYTE)
+ slen = strlen (garglist->word->word+1);
+ mblength = MBLEN (garglist->word->word+1, slen);
+ if (mblength > 1)
+ {
+ mblength = mbtowc (&wc, garglist->word->word+1, slen);
+ ch = wc; /* XXX */
+ }
+ else
+#endif
+ ch = (unsigned char)garglist->word->word[1];
- ch = garglist->word->word[1];
garglist = garglist->next;
return (ch);
}
+
+static SHELL_VAR *
+bind_printf_variable (name, value, flags)
+ char *name;
+ char *value;
+ int flags;
+{
+#if defined (ARRAY_VARS)
+ if (valid_array_reference (name) == 0)
+ return (bind_variable (name, value, flags));
+ else
+ return (assign_array_element (name, value, flags));
+#else /* !ARRAY_VARS */
+ return bind_variable (name, value, flags);
+#endif /* !ARRAY_VARS */
+}
diff --git a/builtins/psize.c b/builtins/psize.c
index 23abb65..30881fb 100644
--- a/builtins/psize.c
+++ b/builtins/psize.c
@@ -4,19 +4,19 @@
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 2, or (at your option)
- any later version.
+ 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.
+ 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; see the file COPYING. If not, write to the Free
- Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
+ along with Bash. If not, see <http://www.gnu.org/licenses/>.
+*/
/* Write output in 128-byte chunks until we get a sigpipe or write gets an
EPIPE. Then report how many bytes we wrote. We assume that this is the
diff --git a/builtins/pushd.def b/builtins/pushd.def
index 86c0bdd..05b7529 100644
--- a/builtins/pushd.def
+++ b/builtins/pushd.def
@@ -1,94 +1,114 @@
This file is pushd.def, from which is created pushd.c. It implements the
builtins "pushd", "popd", and "dirs" in Bash.
-Copyright (C) 1987-2004 Free Software Foundation, Inc.
+Copyright (C) 1987-2009 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 2, or (at your option) any later
-version.
+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.
+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; see the file COPYING. If not, write to the Free Software
-Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
+You should have received a copy of the GNU General Public License
+along with Bash. If not, see <http://www.gnu.org/licenses/>.
$PRODUCES pushd.c
$BUILTIN pushd
$FUNCTION pushd_builtin
$DEPENDS_ON PUSHD_AND_POPD
-$SHORT_DOC pushd [dir | +N | -N] [-n]
+$SHORT_DOC pushd [-n] [+N | -N | dir]
+Add directories to stack.
+
Adds a directory to the top of the directory stack, or rotates
the stack, making the new top of the stack the current working
directory. With no arguments, exchanges the top two directories.
-+N Rotates the stack so that the Nth directory (counting
+Options:
+ -n Suppresses the normal change of directory when adding
+ directories to the stack, so only the stack is manipulated.
+
+Arguments:
+ +N Rotates the stack so that the Nth directory (counting
from the left of the list shown by `dirs', starting with
zero) is at the top.
--N Rotates the stack so that the Nth directory (counting
+ -N Rotates the stack so that the Nth directory (counting
from the right of the list shown by `dirs', starting with
zero) is at the top.
--n suppress the normal change of directory when adding directories
- to the stack, so only the stack is manipulated.
-
-dir adds DIR to the directory stack at the top, making it the
+ dir Adds DIR to the directory stack at the top, making it the
new current working directory.
-You can see the directory stack with the `dirs' command.
+The `dirs' builtin displays the directory stack.
+
+Exit Status:
+Returns success unless an invalid argument is supplied or the directory
+change fails.
$END
$BUILTIN popd
$FUNCTION popd_builtin
$DEPENDS_ON PUSHD_AND_POPD
-$SHORT_DOC popd [+N | -N] [-n]
-Removes entries from the directory stack. With no arguments,
-removes the top directory from the stack, and cd's to the new
-top directory.
+$SHORT_DOC popd [-n] [+N | -N]
+Remove directories from stack.
+
+Removes entries from the directory stack. With no arguments, removes
+the top directory from the stack, and changes to the new top directory.
-+N removes the Nth entry counting from the left of the list
+Options:
+ -n Suppresses the normal change of directory when removing
+ directories from the stack, so only the stack is manipulated.
+
+Arguments:
+ +N Removes the Nth entry counting from the left of the list
shown by `dirs', starting with zero. For example: `popd +0'
removes the first directory, `popd +1' the second.
--N removes the Nth entry counting from the right of the list
+ -N Removes the Nth entry counting from the right of the list
shown by `dirs', starting with zero. For example: `popd -0'
removes the last directory, `popd -1' the next to last.
--n suppress the normal change of directory when removing directories
- from the stack, so only the stack is manipulated.
+The `dirs' builtin displays the directory stack.
-You can see the directory stack with the `dirs' command.
+Exit Status:
+Returns success unless an invalid argument is supplied or the directory
+change fails.
$END
$BUILTIN dirs
$FUNCTION dirs_builtin
$DEPENDS_ON PUSHD_AND_POPD
$SHORT_DOC dirs [-clpv] [+N] [-N]
+Display directory stack.
+
Display the list of currently remembered directories. Directories
find their way onto the list with the `pushd' command; you can get
back up through the list with the `popd' command.
-The -l flag specifies that `dirs' should not print shorthand versions
-of directories which are relative to your home directory. This means
-that `~/bin' might be displayed as `/homes/bfox/bin'. The -v flag
-causes `dirs' to print the directory stack with one entry per line,
-prepending the directory name with its position in the stack. The -p
-flag does the same thing, but the stack position is not prepended.
-The -c flag clears the directory stack by deleting all of the elements.
+Options:
+ -c clear the directory stack by deleting all of the elements
+ -l do not print tilde-prefixed versions of directories relative
+ to your home directory
+ -p print the directory stack with one entry per line
+ -v print the directory stack with one entry per line prefixed
+ with its position in the stack
-+N displays the Nth entry counting from the left of the list shown by
+Arguments:
+ +N Displays the Nth entry counting from the left of the list shown by
dirs when invoked without options, starting with zero.
--N displays the Nth entry counting from the right of the list shown by
+ -N Displays the Nth entry counting from the right of the list shown by
dirs when invoked without options, starting with zero.
+
+Exit Status:
+Returns success unless an invalid option is supplied or an error occurs.
$END
#include <config.h>
@@ -448,7 +468,7 @@ dirs_builtin (list)
if (index_flag)
{
putchar ('\n');
- return EXECUTION_SUCCESS;
+ return (sh_chkwrite (EXECUTION_SUCCESS));
}
}
@@ -473,8 +493,8 @@ dirs_builtin (list)
printf ("%s%s", (vflag & 1) ? "\n" : " ", DIRSTACK_ENTRY (i));
putchar ('\n');
- fflush (stdout);
- return (EXECUTION_SUCCESS);
+
+ return (sh_chkwrite (EXECUTION_SUCCESS));
}
static void
@@ -483,9 +503,9 @@ pushd_error (offset, arg)
char *arg;
{
if (offset == 0)
- builtin_error ("directory stack empty");
+ builtin_error (_("directory stack empty"));
else
- sh_erange (arg, "directory stack index");
+ sh_erange (arg, _("directory stack index"));
}
static void
@@ -660,66 +680,70 @@ get_directory_stack (flags)
#ifdef LOADABLE_BUILTIN
char * const dirs_doc[] = {
- N_("Display the list of currently remembered directories. Directories"),
- N_("find their way onto the list with the `pushd' command; you can get"),
- N_("back up through the list with the `popd' command."),
- N_(" "),
- N_("The -l flag specifies that `dirs' should not print shorthand versions"),
- N_("of directories which are relative to your home directory. This means"),
- N_("that `~/bin' might be displayed as `/homes/bfox/bin'. The -v flag"),
- N_("causes `dirs' to print the directory stack with one entry per line,"),
- N_("prepending the directory name with its position in the stack. The -p"),
- N_("flag does the same thing, but the stack position is not prepended."),
- N_("The -c flag clears the directory stack by deleting all of the elements."),
- N_(" "),
- N_("+N displays the Nth entry counting from the left of the list shown by"),
- N_(" dirs when invoked without options, starting with zero."),
- N_(" "),
- N_("-N displays the Nth entry counting from the right of the list shown by"),
- N_(" dirs when invoked without options, starting with zero."),
+N_("Display the list of currently remembered directories. Directories\n\
+ find their way onto the list with the `pushd' command; you can get\n\
+ back up through the list with the `popd' command.\n\
+ \n\
+ Options:\n\
+ -c clear the directory stack by deleting all of the elements\n\
+ -l do not print tilde-prefixed versions of directories relative\n\
+ to your home directory\n\
+ -p print the directory stack with one entry per line\n\
+ -v print the directory stack with one entry per line prefixed\n\
+ with its position in the stack\n\
+ \n\
+ Arguments:\n\
+ +N Displays the Nth entry counting from the left of the list shown by\n\
+ dirs when invoked without options, starting with zero.\n\
+ \n\
+ -N Displays the Nth entry counting from the right of the list shown by\n\
+ dirs when invoked without options, starting with zero."),
(char *)NULL
};
char * const pushd_doc[] = {
- N_("Adds a directory to the top of the directory stack, or rotates"),
- N_("the stack, making the new top of the stack the current working"),
- N_("directory. With no arguments, exchanges the top two directories."),
- N_(" "),
- N_("+N Rotates the stack so that the Nth directory (counting"),
- N_(" from the left of the list shown by `dirs', starting with"),
- N_(" zero) is at the top."),
- N_(" "),
- N_("-N Rotates the stack so that the Nth directory (counting"),
- N_(" from the right of the list shown by `dirs', starting with"),
- N_(" zero) is at the top."),
- N_(" "),
- N_("-n suppress the normal change of directory when adding directories"),
- N_(" to the stack, so only the stack is manipulated."),
- N_(" "),
- N_("dir adds DIR to the directory stack at the top, making it the"),
- N_(" new current working directory."),
- N_(" "),
- N_("You can see the directory stack with the `dirs' command."),
+N_("Adds a directory to the top of the directory stack, or rotates\n\
+ the stack, making the new top of the stack the current working\n\
+ directory. With no arguments, exchanges the top two directories.\n\
+ \n\
+ Options:\n\
+ -n Suppresses the normal change of directory when adding\n\
+ directories to the stack, so only the stack is manipulated.\n\
+ \n\
+ Arguments:\n\
+ +N Rotates the stack so that the Nth directory (counting\n\
+ from the left of the list shown by `dirs', starting with\n\
+ zero) is at the top.\n\
+ \n\
+ -N Rotates the stack so that the Nth directory (counting\n\
+ from the right of the list shown by `dirs', starting with\n\
+ zero) is at the top.\n\
+ \n\
+ dir Adds DIR to the directory stack at the top, making it the\n\
+ new current working directory.\n\
+ \n\
+ The `dirs' builtin displays the directory stack."),
(char *)NULL
};
char * const popd_doc[] = {
- N_("Removes entries from the directory stack. With no arguments,"),
- N_("removes the top directory from the stack, and cd's to the new"),
- N_("top directory."),
- N_(" "),
- N_("+N removes the Nth entry counting from the left of the list"),
- N_(" shown by `dirs', starting with zero. For example: `popd +0'"),
- N_(" removes the first directory, `popd +1' the second."),
- N_(" "),
- N_("-N removes the Nth entry counting from the right of the list"),
- N_(" shown by `dirs', starting with zero. For example: `popd -0'"),
- N_(" removes the last directory, `popd -1' the next to last."),
- N_(" "),
- N_("-n suppress the normal change of directory when removing directories"),
- N_(" from the stack, so only the stack is manipulated."),
- N_(" "),
- N_("You can see the directory stack with the `dirs' command."),
+N_("Removes entries from the directory stack. With no arguments, removes\n\
+ the top directory from the stack, and changes to the new top directory.\n\
+ \n\
+ Options:\n\
+ -n Suppresses the normal change of directory when removing\n\
+ directories from the stack, so only the stack is manipulated.\n\
+ \n\
+ Arguments:\n\
+ +N Removes the Nth entry counting from the left of the list\n\
+ shown by `dirs', starting with zero. For example: `popd +0'\n\
+ removes the first directory, `popd +1' the second.\n\
+ \n\
+ -N Removes the Nth entry counting from the right of the list\n\
+ shown by `dirs', starting with zero. For example: `popd -0'\n\
+ removes the last directory, `popd -1' the next to last.\n\
+ \n\
+ The `dirs' builtin displays the directory stack."),
(char *)NULL
};
diff --git a/builtins/read.def b/builtins/read.def
index 21521db..1ef9142 100644
--- a/builtins/read.def
+++ b/builtins/read.def
@@ -1,50 +1,66 @@
This file is read.def, from which is created read.c.
It implements the builtin "read" in Bash.
-Copyright (C) 1987-2005 Free Software Foundation, Inc.
+Copyright (C) 1987-2009 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 2, or (at your option) any later
-version.
+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.
+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; see the file COPYING. If not, write to the Free Software
-Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
+You should have received a copy of the GNU General Public License
+along with Bash. If not, see <http://www.gnu.org/licenses/>.
$PRODUCES read.c
$BUILTIN read
$FUNCTION read_builtin
-$SHORT_DOC read [-ers] [-u fd] [-t timeout] [-p prompt] [-a array] [-n nchars] [-d delim] [name ...]
-One line is read from the standard input, or from file descriptor FD if the
--u option is supplied, and the first word is assigned to the first NAME,
-the second word to the second NAME, and so on, with leftover words assigned
-to the last NAME. Only the characters found in $IFS are recognized as word
-delimiters. If no NAMEs are supplied, the line read is stored in the REPLY
-variable. If the -r option is given, this signifies `raw' input, and
-backslash escaping is disabled. The -d option causes read to continue
-until the first character of DELIM is read, rather than newline. If the -p
-option is supplied, the string PROMPT is output without a trailing newline
-before attempting to read. If -a is supplied, the words read are assigned
-to sequential indices of ARRAY, starting at zero. If -e is supplied and
-the shell is interactive, readline is used to obtain the line. If -n is
-supplied with a non-zero NCHARS argument, read returns after NCHARS
-characters have been read. The -s option causes input coming from a
-terminal to not be echoed.
-
-The -t option causes read to time out and return failure if a complete line
-of input is not read within TIMEOUT seconds. If the TMOUT variable is set,
-its value is the default timeout. The return code is zero, unless end-of-file
-is encountered, read times out, or an invalid file descriptor is supplied as
-the argument to -u.
+$SHORT_DOC read [-ers] [-a array] [-d delim] [-i text] [-n nchars] [-N nchars] [-p prompt] [-t timeout] [-u fd] [name ...]
+Read a line from the standard input and split it into fields.
+
+Reads a single line from the standard input, or from file descriptor FD
+if the -u option is supplied. The line is split into fields as with word
+splitting, and the first word is assigned to the first NAME, the second
+word to the second NAME, and so on, with any leftover words assigned to
+the last NAME. Only the characters found in $IFS are recognized as word
+delimiters.
+
+If no NAMEs are supplied, the line read is stored in the REPLY variable.
+
+Options:
+ -a array assign the words read to sequential indices of the array
+ variable ARRAY, starting at zero
+ -d delim continue until the first character of DELIM is read, rather
+ than newline
+ -e use Readline to obtain the line in an interactive shell
+ -i text Use TEXT as the initial text for Readline
+ -n nchars return after reading NCHARS characters rather than waiting
+ for a newline, but honor a delimiter if fewer than NCHARS
+ characters are read before the delimiter
+ -N nchars return only after reading exactly NCHARS characters, unless
+ EOF is encountered or read times out, ignoring any delimiter
+ -p prompt output the string PROMPT without a trailing newline before
+ attempting to read
+ -r do not allow backslashes to escape any characters
+ -s do not echo input coming from a terminal
+ -t timeout time out and return failure if a complete line of input is
+ not read withint TIMEOUT seconds. The value of the TMOUT
+ variable is the default timeout. TIMEOUT may be a
+ fractional number. If TIMEOUT is 0, read returns success only
+ if input is available on the specified file descriptor. The
+ exit status is greater than 128 if the timeout is exceeded
+ -u fd read from file descriptor FD instead of the standard input
+
+Exit Status:
+The return code is zero, unless end-of-file is encountered, read times out,
+or an invalid file descriptor is supplied as the argument to -u.
$END
#include <config.h>
@@ -54,6 +70,8 @@ $END
#include <stdio.h>
+#include "bashansi.h"
+
#if defined (HAVE_UNISTD_H)
# include <unistd.h>
#endif
@@ -87,13 +105,24 @@ $END
extern int errno;
#endif
+struct ttsave
+{
+ int fd;
+ TTYSTRUCT *attrs;
+};
+
#if defined (READLINE)
static void reset_attempted_completion_function __P((char *));
-static char *edit_line __P((char *));
+static int set_itext __P((void));
+static char *edit_line __P((char *, char *));
static void set_eol_delim __P((int));
static void reset_eol_delim __P((char *));
#endif
static SHELL_VAR *bind_read_variable __P((char *, char *));
+#if defined (HANDLE_MULTIBYTE)
+static int read_mbchar __P((int, char *, int, int, int));
+#endif
+static void ttyrestore __P((struct ttsave *));
static sighandler sigalrm __P((int));
static void reset_alarm __P((void));
@@ -113,7 +142,7 @@ static void
reset_alarm ()
{
set_signal_handler (SIGALRM, old_alrm);
- alarm (0);
+ falarm (0, 0);
}
/* Read the value of the shell variables whose names follow.
@@ -127,32 +156,37 @@ read_builtin (list)
WORD_LIST *list;
{
register char *varname;
- int size, i, nr, pass_next, saw_escape, eof, opt, retval, code;
- int input_is_tty, input_is_pipe, unbuffered_read;
- int raw, edit, nchars, silent, have_timeout, fd;
- unsigned int tmout;
+ int size, i, nr, pass_next, saw_escape, eof, opt, retval, code, print_ps2;
+ int input_is_tty, input_is_pipe, unbuffered_read, skip_ctlesc, skip_ctlnul;
+ int raw, edit, nchars, silent, have_timeout, ignore_delim, fd;
+ unsigned int tmsec, tmusec;
+ long ival, uval;
intmax_t intval;
char c;
char *input_string, *orig_input_string, *ifs_chars, *prompt, *arrayname;
- char *e, *t, *t1;
+ char *e, *t, *t1, *ps2, *tofree;
struct stat tsb;
SHELL_VAR *var;
+ TTYSTRUCT ttattrs, ttset;
+ struct ttsave termsave;
#if defined (ARRAY_VARS)
WORD_LIST *alist;
#endif
#if defined (READLINE)
- char *rlbuf;
+ char *rlbuf, *itext;
int rlind;
#endif
USE_VAR(size);
USE_VAR(i);
USE_VAR(pass_next);
+ USE_VAR(print_ps2);
USE_VAR(saw_escape);
USE_VAR(input_is_pipe);
/* USE_VAR(raw); */
USE_VAR(edit);
- USE_VAR(tmout);
+ USE_VAR(tmsec);
+ USE_VAR(tmusec);
USE_VAR(nchars);
USE_VAR(silent);
USE_VAR(ifs_chars);
@@ -161,8 +195,10 @@ read_builtin (list)
#if defined (READLINE)
USE_VAR(rlbuf);
USE_VAR(rlind);
+ USE_VAR(itext);
#endif
USE_VAR(list);
+ USE_VAR(ps2);
i = 0; /* Index into the string that we are reading. */
raw = edit = 0; /* Not reading raw input by default. */
@@ -171,16 +207,17 @@ read_builtin (list)
fd = 0; /* file descriptor to read from */
#if defined (READLINE)
- rlbuf = (char *)0;
+ rlbuf = itext = (char *)0;
rlind = 0;
#endif
- tmout = 0; /* no timeout */
+ tmsec = tmusec = 0; /* no timeout */
nr = nchars = input_is_tty = input_is_pipe = unbuffered_read = have_timeout = 0;
delim = '\n'; /* read until newline */
+ ignore_delim = 0;
reset_internal_getopt ();
- while ((opt = internal_getopt (list, "ersa:d:n:p:t:u:")) != -1)
+ while ((opt = internal_getopt (list, "ersa:d:i:n:p:t:u:N:")) != -1)
{
switch (opt)
{
@@ -198,14 +235,19 @@ read_builtin (list)
edit = 1;
#endif
break;
+ case 'i':
+#if defined (READLINE)
+ itext = list_optarg;
+#endif
+ break;
#if defined (ARRAY_VARS)
case 'a':
arrayname = list_optarg;
break;
#endif
case 't':
- code = legal_number (list_optarg, &intval);
- if (code == 0 || intval < 0 || intval != (unsigned int)intval)
+ code = uconvert (list_optarg, &ival, &uval);
+ if (code == 0 || ival < 0 || uval < 0)
{
builtin_error (_("%s: invalid timeout specification"), list_optarg);
return (EXECUTION_FAILURE);
@@ -213,9 +255,13 @@ read_builtin (list)
else
{
have_timeout = 1;
- tmout = intval;
+ tmsec = ival;
+ tmusec = uval;
}
break;
+ case 'N':
+ ignore_delim = 1;
+ delim = -1;
case 'n':
code = legal_number (list_optarg, &intval);
if (code == 0 || intval < 0 || intval != (int)intval)
@@ -251,27 +297,43 @@ read_builtin (list)
}
list = loptend;
- /* `read -t 0 var' returns failure immediately. XXX - should it test
- whether input is available with select/FIONREAD, and fail if those
- are unavailable? */
- if (have_timeout && tmout == 0)
+ /* `read -t 0 var' tests whether input is available with select/FIONREAD,
+ and fails if those are unavailable */
+ if (have_timeout && tmsec == 0 && tmusec == 0)
+#if 0
return (EXECUTION_FAILURE);
+#else
+ return (input_avail (fd) ? EXECUTION_SUCCESS : EXECUTION_FAILURE);
+#endif
+
+ /* If we're asked to ignore the delimiter, make sure we do. */
+ if (ignore_delim)
+ delim = -1;
/* IF IFS is unset, we use the default of " \t\n". */
ifs_chars = getifs ();
if (ifs_chars == 0) /* XXX - shouldn't happen */
ifs_chars = "";
+ /* If we want to read exactly NCHARS chars, don't split on IFS */
+ if (ignore_delim)
+ ifs_chars = "";
+ for (skip_ctlesc = skip_ctlnul = 0, e = ifs_chars; *e; e++)
+ skip_ctlesc |= *e == CTLESC, skip_ctlnul |= *e == CTLNUL;
input_string = (char *)xmalloc (size = 112); /* XXX was 128 */
+ input_string[0] = '\0';
/* $TMOUT, if set, is the default timeout for read. */
if (have_timeout == 0 && (e = get_string_value ("TMOUT")))
{
- code = legal_number (e, &intval);
- if (code == 0 || intval < 0 || intval != (unsigned int)intval)
- tmout = 0;
+ code = uconvert (e, &ival, &uval);
+ if (code == 0 || ival < 0 || uval < 0)
+ tmsec = tmusec = 0;
else
- tmout = intval;
+ {
+ tmsec = ival;
+ tmusec = uval;
+ }
}
begin_unwind_frame ("read_builtin");
@@ -294,6 +356,9 @@ read_builtin (list)
if ((prompt || edit || silent) && input_is_tty == 0)
{
prompt = (char *)NULL;
+#if defined (READLINE)
+ itext = (char *)NULL;
+#endif
edit = silent = 0;
}
@@ -302,30 +367,30 @@ read_builtin (list)
add_unwind_protect (xfree, rlbuf);
#endif
- if (prompt && edit == 0)
- {
- fprintf (stderr, "%s", prompt);
- fflush (stderr);
- }
-
pass_next = 0; /* Non-zero signifies last char was backslash. */
saw_escape = 0; /* Non-zero signifies that we saw an escape char */
- if (tmout > 0)
+ if (tmsec > 0 || tmusec > 0)
{
/* Turn off the timeout if stdin is a regular file (e.g. from
input redirection). */
if ((fstat (fd, &tsb) < 0) || S_ISREG (tsb.st_mode))
- tmout = 0;
+ tmsec = tmusec = 0;
}
- if (tmout > 0)
+ if (tmsec > 0 || tmusec > 0)
{
code = setjmp (alrmbuf);
if (code)
{
+ /* Tricky. The top of the unwind-protect stack is the free of
+ input_string. We want to run all the rest and use input_string,
+ so we have to remove it from the stack. */
+ remove_unwind_protect ();
run_unwind_frame ("read_builtin");
- return (EXECUTION_FAILURE);
+ input_string[i] = '\0'; /* make sure it's terminated */
+ retval = 128+SIGALRM;
+ goto assign_vars;
}
old_alrm = set_signal_handler (SIGALRM, sigalrm);
add_unwind_protect (reset_alarm, (char *)NULL);
@@ -333,7 +398,7 @@ read_builtin (list)
if (edit)
add_unwind_protect (reset_attempted_completion_function, (char *)NULL);
#endif
- alarm (tmout);
+ falarm (tmsec, tmusec);
}
/* If we've been asked to read only NCHARS chars, or we're using some
@@ -359,34 +424,53 @@ read_builtin (list)
#endif
if (input_is_tty)
{
- ttsave ();
- if (silent)
- ttcbreak ();
- else
- ttonechar ();
- add_unwind_protect ((Function *)ttrestore, (char *)NULL);
+ /* ttsave() */
+ termsave.fd = fd;
+ ttgetattr (fd, &ttattrs);
+ termsave.attrs = &ttattrs;
+
+ ttset = ttattrs;
+ i = silent ? ttfd_cbreak (fd, &ttset) : ttfd_onechar (fd, &ttset);
+ if (i < 0)
+ sh_ttyerror (1);
+ add_unwind_protect ((Function *)ttyrestore, (char *)&termsave);
}
}
else if (silent) /* turn off echo but leave term in canonical mode */
{
- ttsave ();
- ttnoecho ();
- add_unwind_protect ((Function *)ttrestore, (char *)NULL);
+ /* ttsave (); */
+ termsave.fd = fd;
+ ttgetattr (fd, &ttattrs);
+ termsave.attrs = &ttattrs;
+
+ ttset = ttattrs;
+ i = ttfd_noecho (fd, &ttset); /* ttnoecho (); */
+ if (i < 0)
+ sh_ttyerror (1);
+
+ add_unwind_protect ((Function *)ttyrestore, (char *)&termsave);
}
/* This *must* be the top unwind-protect on the stack, so the manipulation
of the unwind-protect stack after the realloc() works right. */
add_unwind_protect (xfree, input_string);
interrupt_immediately++;
- terminate_immediately = 1;
+ terminate_immediately++;
unbuffered_read = (nchars > 0) || (delim != '\n') || input_is_pipe;
+ if (prompt && edit == 0)
+ {
+ fprintf (stderr, "%s", prompt);
+ fflush (stderr);
+ }
+
#if defined (__CYGWIN__) && defined (O_TEXT)
setmode (0, O_TEXT);
#endif
- for (eof = retval = 0;;)
+ ps2 = 0;
+ for (print_ps2 = eof = retval = 0;;)
{
#if defined (READLINE)
if (edit)
@@ -398,7 +482,7 @@ read_builtin (list)
}
if (rlbuf == 0)
{
- rlbuf = edit_line (prompt ? prompt : "");
+ rlbuf = edit_line (prompt ? prompt : "", itext);
rlind = 0;
}
if (rlbuf == 0)
@@ -412,6 +496,15 @@ read_builtin (list)
{
#endif
+ if (print_ps2)
+ {
+ if (ps2 == 0)
+ ps2 = get_string_value ("PS2");
+ fprintf (stderr, "%s", ps2 ? ps2 : "");
+ fflush (stderr);
+ print_ps2 = 0;
+ }
+
if (unbuffered_read)
retval = zread (fd, &c, 1);
else
@@ -427,7 +520,7 @@ read_builtin (list)
}
#endif
- if (i + 2 >= size)
+ if (i + 4 >= size) /* XXX was i + 2; use i + 4 for multibyte/read_mbchar */
{
input_string = (char *)xrealloc (input_string, size += 128);
remove_unwind_protect ();
@@ -440,24 +533,32 @@ read_builtin (list)
{
pass_next = 0;
if (c == '\n')
- i--; /* back up over the CTLESC */
+ {
+ i--; /* back up over the CTLESC */
+ if (interactive && input_is_tty && raw == 0)
+ print_ps2 = 1;
+ }
else
goto add_char;
continue;
}
+ /* This may cause problems if IFS contains CTLESC */
if (c == '\\' && raw == 0)
{
pass_next++;
- saw_escape++;
- input_string[i++] = CTLESC;
+ if (skip_ctlesc == 0)
+ {
+ saw_escape++;
+ input_string[i++] = CTLESC;
+ }
continue;
}
if ((unsigned char)c == delim)
break;
- if (c == CTLESC || c == CTLNUL)
+ if ((skip_ctlesc == 0 && c == CTLESC) || (skip_ctlnul == 0 && c == CTLNUL))
{
saw_escape++;
input_string[i++] = CTLESC;
@@ -465,6 +566,15 @@ read_builtin (list)
add_char:
input_string[i++] = c;
+
+#if defined (HANDLE_MULTIBYTE)
+ if (nchars > 0 && MB_CUR_MAX > 1)
+ {
+ input_string[i] = '\0'; /* for simplicity and debugging */
+ i += read_mbchar (fd, input_string, i, c, unbuffered_read);
+ }
+#endif
+
nr++;
if (nchars > 0 && nr >= nchars)
@@ -481,7 +591,7 @@ add_char:
}
#endif
- if (tmout > 0)
+ if (tmsec > 0 || tmusec > 0)
reset_alarm ();
if (nchars > 0 || delim != '\n')
@@ -497,20 +607,22 @@ add_char:
else
#endif
if (input_is_tty)
- ttrestore ();
+ ttyrestore (&termsave);
}
else if (silent)
- ttrestore ();
+ ttyrestore (&termsave);
if (unbuffered_read == 0)
zsyncfd (fd);
interrupt_immediately--;
- terminate_immediately = 0;
+ terminate_immediately--;
discard_unwind_frame ("read_builtin");
retval = eof ? EXECUTION_FAILURE : EXECUTION_SUCCESS;
+assign_vars:
+
#if defined (ARRAY_VARS)
/* If -a was given, take the string read, break it into a list of words,
an assign them to `arrayname' in turn. */
@@ -587,7 +699,6 @@ add_char:
for (t = input_string; ifs_chars && *ifs_chars && spctabnl(*t) && isifs(*t); t++)
;
input_string = t;
-
for (; list->next; list = list->next)
{
varname = list->word->word;
@@ -658,14 +769,18 @@ add_char:
#else
/* Check whether or not the number of fields is exactly the same as the
number of variables. */
+ tofree = NULL;
if (*input_string)
{
t1 = input_string;
t = get_word_from_string (&input_string, ifs_chars, &e);
if (*input_string == 0)
- input_string = t;
+ tofree = input_string = t;
else
- input_string = strip_trailing_ifs_whitespace (t1, ifs_chars, saw_escape);
+ {
+ input_string = strip_trailing_ifs_whitespace (t1, ifs_chars, saw_escape);
+ tofree = t;
+ }
}
#endif
@@ -678,6 +793,8 @@ add_char:
else
var = bind_read_variable (list->word->word, input_string);
stupidly_hack_special_variables (list->word->word);
+ FREE (tofree);
+
if (var)
VUNSETATTR (var, att_invisible);
xfree (orig_input_string);
@@ -699,8 +816,66 @@ bind_read_variable (name, value)
#endif /* !ARRAY_VARS */
}
+#if defined (HANDLE_MULTIBYTE)
+static int
+read_mbchar (fd, string, ind, ch, unbuffered)
+ int fd;
+ char *string;
+ int ind, ch, unbuffered;
+{
+ char mbchar[MB_LEN_MAX + 1];
+ int i, n, r;
+ char c;
+ size_t ret;
+ mbstate_t ps, ps_back;
+ wchar_t wc;
+
+ memset (&ps, '\0', sizeof (mbstate_t));
+ memset (&ps_back, '\0', sizeof (mbstate_t));
+
+ mbchar[0] = ch;
+ i = 1;
+ for (n = 0; n <= MB_LEN_MAX; n++)
+ {
+ ps_back = ps;
+ ret = mbrtowc (&wc, mbchar, i, &ps);
+ if (ret == (size_t)-2)
+ {
+ ps = ps_back;
+ if (unbuffered)
+ r = zread (fd, &c, 1);
+ else
+ r = zreadc (fd, &c);
+ if (r < 0)
+ goto mbchar_return;
+ mbchar[i++] = c;
+ continue;
+ }
+ else if (ret == (size_t)-1 || ret == (size_t)0 || ret > (size_t)0)
+ break;
+ }
+
+mbchar_return:
+ if (i > 1) /* read a multibyte char */
+ /* mbchar[0] is already string[ind-1] */
+ for (r = 1; r < i; r++)
+ string[ind+r-1] = mbchar[r];
+ return i - 1;
+}
+#endif
+
+
+static void
+ttyrestore (ttp)
+ struct ttsave *ttp;
+{
+ ttsetattr (ttp->fd, ttp->attrs);
+}
+
#if defined (READLINE)
static rl_completion_func_t *old_attempted_completion_function = 0;
+static rl_hook_func_t *old_startup_hook;
+static char *deftext;
static void
reset_attempted_completion_function (cp)
@@ -710,9 +885,28 @@ reset_attempted_completion_function (cp)
rl_attempted_completion_function = old_attempted_completion_function;
}
+static int
+set_itext ()
+{
+ int r1, r2;
+
+ r1 = r2 = 0;
+ if (old_startup_hook)
+ r1 = (*old_startup_hook) ();
+ if (deftext)
+ {
+ r2 = rl_insert_text (deftext);
+ deftext = (char *)NULL;
+ rl_startup_hook = old_startup_hook;
+ old_startup_hook = (rl_hook_func_t *)NULL;
+ }
+ return (r1 || r2);
+}
+
static char *
-edit_line (p)
+edit_line (p, itext)
char *p;
+ char *itext;
{
char *ret;
int len;
@@ -722,6 +916,12 @@ edit_line (p)
old_attempted_completion_function = rl_attempted_completion_function;
rl_attempted_completion_function = (rl_completion_func_t *)NULL;
+ if (itext)
+ {
+ old_startup_hook = rl_startup_hook;
+ rl_startup_hook = set_itext;
+ deftext = itext;
+ }
ret = readline (p);
rl_attempted_completion_function = old_attempted_completion_function;
old_attempted_completion_function = (rl_completion_func_t *)NULL;
diff --git a/builtins/reserved.def b/builtins/reserved.def
index e968ec7..2478f16 100644
--- a/builtins/reserved.def
+++ b/builtins/reserved.def
@@ -2,35 +2,41 @@ This file is reserved.def, in which the shell reserved words are defined.
It has no direct C file production, but defines builtins for the Bash
builtin help command.
-Copyright (C) 1987-2006 Free Software Foundation, Inc.
+Copyright (C) 1987-2009 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 2, or (at your option) any later
-version.
+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.
+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; see the file COPYING. If not, write to the Free Software
-Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
+You should have received a copy of the GNU General Public License
+along with Bash. If not, see <http://www.gnu.org/licenses/>.
$BUILTIN for
-$SHORT_DOC for NAME [in WORDS ... ;] do COMMANDS; done
+$SHORT_DOC for NAME [in WORDS ... ] ; do COMMANDS; done
+Execute commands for each member in a list.
+
The `for' loop executes a sequence of commands for each member in a
list of items. If `in WORDS ...;' is not present, then `in "$@"' is
assumed. For each element in WORDS, NAME is set to that element, and
the COMMANDS are executed.
+
+Exit Status:
+Returns the status of the last command executed.
$END
$BUILTIN for ((
$DOCNAME arith_for
$SHORT_DOC for (( exp1; exp2; exp3 )); do COMMANDS; done
+Arithmetic for loop.
+
Equivalent to
(( EXP1 ))
while (( EXP2 )); do
@@ -39,10 +45,15 @@ Equivalent to
done
EXP1, EXP2, and EXP3 are arithmetic expressions. If any expression is
omitted, it behaves as if it evaluates to 1.
+
+Exit Status:
+Returns the status of the last command executed.
$END
$BUILTIN select
$SHORT_DOC select NAME [in WORDS ... ;] do COMMANDS; done
+Select words from a list and execute commands.
+
The WORDS are expanded, generating a list of words. The
set of expanded words is printed on the standard error, each
preceded by a number. If `in WORDS' is not present, `in "$@"'
@@ -54,25 +65,42 @@ redisplayed. If EOF is read, the command completes. Any other
value read causes NAME to be set to null. The line read is saved
in the variable REPLY. COMMANDS are executed after each selection
until a break command is executed.
+
+Exit Status:
+Returns the status of the last command executed.
$END
$BUILTIN time
-$SHORT_DOC time [-p] PIPELINE
+$SHORT_DOC time [-p] pipeline
+Report time consumed by pipeline's execution.
+
Execute PIPELINE and print a summary of the real time, user CPU time,
and system CPU time spent executing PIPELINE when it terminates.
-The return status is the return status of PIPELINE. The `-p' option
-prints the timing summary in a slightly different format. This uses
-the value of the TIMEFORMAT variable as the output format.
+
+Options:
+ -p print the timing summary in the portable Posix format
+
+The value of the TIMEFORMAT variable is used as the output format.
+
+Exit Status:
+The return status is the return status of PIPELINE.
$END
$BUILTIN case
$SHORT_DOC case WORD in [PATTERN [| PATTERN]...) COMMANDS ;;]... esac
+Execute commands based on pattern matching.
+
Selectively execute COMMANDS based upon WORD matching PATTERN. The
`|' is used to separate multiple patterns.
+
+Exit Status:
+Returns the status of the last command executed.
$END
$BUILTIN if
$SHORT_DOC if COMMANDS; then COMMANDS; [ elif COMMANDS; then COMMANDS; ]... [ else COMMANDS; ] fi
+Execute commands based on conditional.
+
The `if COMMANDS' list is executed. If its exit status is zero, then the
`then COMMANDS' list is executed. Otherwise, each `elif COMMANDS' list is
executed in turn, and if its exit status is zero, the corresponding
@@ -80,75 +108,132 @@ executed in turn, and if its exit status is zero, the corresponding
the `else COMMANDS' list is executed, if present. The exit status of the
entire construct is the exit status of the last command executed, or zero
if no condition tested true.
+
+Exit Status:
+Returns the status of the last command executed.
$END
$BUILTIN while
$SHORT_DOC while COMMANDS; do COMMANDS; done
+Execute commands as long as a test succeeds.
+
Expand and execute COMMANDS as long as the final command in the
`while' COMMANDS has an exit status of zero.
+
+Exit Status:
+Returns the status of the last command executed.
$END
$BUILTIN until
$SHORT_DOC until COMMANDS; do COMMANDS; done
+Execute commands as long as a test does not succeed.
+
Expand and execute COMMANDS as long as the final command in the
`until' COMMANDS has an exit status which is not zero.
+
+Exit Status:
+Returns the status of the last command executed.
+$END
+
+$BUILTIN coproc
+$SHORT_DOC coproc [NAME] command [redirections]
+Create a coprocess named NAME.
+
+Execute COMMAND asynchronously, with the standard output and standard
+input of the command connected via a pipe to file descriptors assigned
+to indices 0 and 1 of an array variable NAME in the executing shell.
+The default NAME is "COPROC".
+
+Exit Status:
+Returns the exit status of COMMAND.
$END
$BUILTIN function
-$SHORT_DOC function NAME { COMMANDS ; } or NAME () { COMMANDS ; }
-Create a simple command invoked by NAME which runs COMMANDS.
-Arguments on the command line along with NAME are passed to the
-function as $0 .. $n.
+$SHORT_DOC function name { COMMANDS ; } or name () { COMMANDS ; }
+Define shell function.
+
+Create a shell function named NAME. When invoked as a simple command,
+NAME runs COMMANDs in the calling shell's context. When NAME is invoked,
+the arguments are passed to the function as $1...$n, and the function's
+name is in $FUNCNAME.
+
+Exit Status:
+Returns success unless NAME is readonly.
$END
$BUILTIN { ... }
$DOCNAME grouping_braces
$SHORT_DOC { COMMANDS ; }
+Group commands as a unit.
+
Run a set of commands in a group. This is one way to redirect an
entire set of commands.
+
+Exit Status:
+Returns the status of the last command executed.
$END
$BUILTIN %
$DOCNAME fg_percent
-$SHORT_DOC JOB_SPEC [&]
+$SHORT_DOC job_spec [&]
+Resume job in foreground.
+
Equivalent to the JOB_SPEC argument to the `fg' command. Resume a
stopped or background job. JOB_SPEC can specify either a job name
or a job number. Following JOB_SPEC with a `&' places the job in
the background, as if the job specification had been supplied as an
argument to `bg'.
+
+Exit Status:
+Returns the status of the resumed job.
$END
$BUILTIN (( ... ))
$DOCNAME arith
$SHORT_DOC (( expression ))
+Evaluate arithmetic expression.
+
The EXPRESSION is evaluated according to the rules for arithmetic
evaluation. Equivalent to "let EXPRESSION".
+
+Exit Status:
+Returns 1 if EXPRESSION evaluates to 0; returns 0 otherwise.
$END
$BUILTIN [[ ... ]]
$DOCNAME conditional
$SHORT_DOC [[ expression ]]
+Execute conditional command.
+
Returns a status of 0 or 1 depending on the evaluation of the conditional
expression EXPRESSION. Expressions are composed of the same primaries used
-by the `test' builtin, and may be combined using the following operators
+by the `test' builtin, and may be combined using the following operators:
+
+ ( EXPRESSION ) Returns the value of EXPRESSION
+ ! EXPRESSION True if EXPRESSION is false; else false
+ EXPR1 && EXPR2 True if both EXPR1 and EXPR2 are true; else false
+ EXPR1 || EXPR2 True if either EXPR1 or EXPR2 is true; else false
- ( EXPRESSION ) Returns the value of EXPRESSION
- ! EXPRESSION True if EXPRESSION is false; else false
- EXPR1 && EXPR2 True if both EXPR1 and EXPR2 are true; else false
- EXPR1 || EXPR2 True if either EXPR1 or EXPR2 is true; else false
+When the `==' and `!=' operators are used, the string to the right of
+the operator is used as a pattern and pattern matching is performed.
+When the `=~' operator is used, the string to the right of the operator
+is matched as a regular expression.
-When the `==' and `!=' operators are used, the string to the right of the
-operator is used as a pattern and pattern matching is performed. The
-&& and || operators do not evaluate EXPR2 if EXPR1 is sufficient to
+The && and || operators do not evaluate EXPR2 if EXPR1 is sufficient to
determine the expression's value.
+
+Exit Status:
+0 or 1 depending on value of EXPRESSION.
$END
$BUILTIN variables
$DOCNAME variable_help
-$SHORT_DOC variables - Some variable names and meanings
+$SHORT_DOC variables - Names and meanings of some shell variables
+Common shell variable names and usage.
+
BASH_VERSION Version information for this Bash.
CDPATH A colon-separated list of directories to search
- for directries given as arguments to `cd'.
+ for directories given as arguments to `cd'.
GLOBIGNORE A colon-separated list of patterns describing filenames to
be ignored by pathname expansion.
#if defined (HISTORY)
diff --git a/builtins/return.def b/builtins/return.def
index 23389c0..641ee16 100644
--- a/builtins/return.def
+++ b/builtins/return.def
@@ -1,23 +1,22 @@
This file is return.def, from which is created return.c.
It implements the builtin "return" in Bash.
-Copyright (C) 1987-2003 Free Software Foundation, Inc.
+Copyright (C) 1987-2009 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 2, or (at your option) any later
-version.
+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.
+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; see the file COPYING. If not, write to the Free Software
-Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
+You should have received a copy of the GNU General Public License
+along with Bash. If not, see <http://www.gnu.org/licenses/>.
$PRODUCES return.c
@@ -25,8 +24,14 @@ $BUILTIN return
$FUNCTION return_builtin
$SHORT_DOC return [n]
-Causes a function to exit with the return value specified by N. If N
-is omitted, the return status is that of the last command.
+Return from a shell function.
+
+Causes a function or sourced script to exit with the return value
+specified by N. If N is omitted, the return status is that of the
+last command executed within the function or script.
+
+Exit Status:
+Returns N, or failure if the shell is not executing a function or script.
$END
#include <config.h>
@@ -42,6 +47,7 @@ $END
#include "../shell.h"
#include "common.h"
+#include "bashgetopt.h"
extern int last_command_exit_value;
extern int subshell_environment;
@@ -54,6 +60,10 @@ int
return_builtin (list)
WORD_LIST *list;
{
+ if (no_options (list))
+ return (EX_USAGE);
+ list = loptend; /* skip over possible `--' */
+
return_catch_value = get_exitstat (list);
if (return_catch_flag)
diff --git a/builtins/set.def b/builtins/set.def
index d108669..5e550cb 100644
--- a/builtins/set.def
+++ b/builtins/set.def
@@ -1,23 +1,22 @@
This file is set.def, from which is created set.c.
It implements the "set" and "unset" builtins in Bash.
-Copyright (C) 1987-2004 Free Software Foundation, Inc.
+Copyright (C) 1987-2009 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 2, or (at your option) any later
-version.
+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.
+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; see the file COPYING. If not, write to the Free Software
-Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
+You should have received a copy of the GNU General Public License
+along with Bash. If not, see <http://www.gnu.org/licenses/>.
$PRODUCES set.c
@@ -60,87 +59,96 @@ extern int no_line_editing;
$BUILTIN set
$FUNCTION set_builtin
-$SHORT_DOC set [--abefhkmnptuvxBCHP] [-o option] [arg ...]
- -a Mark variables which are modified or created for export.
- -b Notify of job termination immediately.
- -e Exit immediately if a command exits with a non-zero status.
- -f Disable file name generation (globbing).
- -h Remember the location of commands as they are looked up.
- -k All assignment arguments are placed in the environment for a
- command, not just those that precede the command name.
- -m Job control is enabled.
- -n Read commands but do not execute them.
- -o option-name
- Set the variable corresponding to option-name:
- allexport same as -a
- braceexpand same as -B
+$SHORT_DOC set [--abefhkmnptuvxBCHP] [-o option-name] [arg ...]
+Set or unset values of shell options and positional parameters.
+
+Change the value of shell attributes and positional parameters, or
+display the names and values of shell variables.
+
+Options:
+ -a Mark variables which are modified or created for export.
+ -b Notify of job termination immediately.
+ -e Exit immediately if a command exits with a non-zero status.
+ -f Disable file name generation (globbing).
+ -h Remember the location of commands as they are looked up.
+ -k All assignment arguments are placed in the environment for a
+ command, not just those that precede the command name.
+ -m Job control is enabled.
+ -n Read commands but do not execute them.
+ -o option-name
+ Set the variable corresponding to option-name:
+ allexport same as -a
+ braceexpand same as -B
#if defined (READLINE)
- emacs use an emacs-style line editing interface
+ emacs use an emacs-style line editing interface
#endif /* READLINE */
- errexit same as -e
- errtrace same as -E
- functrace same as -T
- hashall same as -h
+ errexit same as -e
+ errtrace same as -E
+ functrace same as -T
+ hashall same as -h
#if defined (BANG_HISTORY)
- histexpand same as -H
+ histexpand same as -H
#endif /* BANG_HISTORY */
#if defined (HISTORY)
- history enable command history
+ history enable command history
#endif
- ignoreeof the shell will not exit upon reading EOF
- interactive-comments
- allow comments to appear in interactive commands
- keyword same as -k
- monitor same as -m
- noclobber same as -C
- noexec same as -n
- noglob same as -f
- nolog currently accepted but ignored
- notify same as -b
- nounset same as -u
- onecmd same as -t
- physical same as -P
- pipefail the return value of a pipeline is the status of
- the last command to exit with a non-zero status,
- or zero if no command exited with a non-zero status
- posix change the behavior of bash where the default
- operation differs from the 1003.2 standard to
- match the standard
- privileged same as -p
- verbose same as -v
+ ignoreeof the shell will not exit upon reading EOF
+ interactive-comments
+ allow comments to appear in interactive commands
+ keyword same as -k
+ monitor same as -m
+ noclobber same as -C
+ noexec same as -n
+ noglob same as -f
+ nolog currently accepted but ignored
+ notify same as -b
+ nounset same as -u
+ onecmd same as -t
+ physical same as -P
+ pipefail the return value of a pipeline is the status of
+ the last command to exit with a non-zero status,
+ or zero if no command exited with a non-zero status
+ posix change the behavior of bash where the default
+ operation differs from the Posix standard to
+ match the standard
+ privileged same as -p
+ verbose same as -v
#if defined (READLINE)
- vi use a vi-style line editing interface
+ vi use a vi-style line editing interface
#endif /* READLINE */
- xtrace same as -x
- -p Turned on whenever the real and effective user ids do not match.
- Disables processing of the $ENV file and importing of shell
- functions. Turning this option off causes the effective uid and
- gid to be set to the real uid and gid.
- -t Exit after reading and executing one command.
- -u Treat unset variables as an error when substituting.
- -v Print shell input lines as they are read.
- -x Print commands and their arguments as they are executed.
+ xtrace same as -x
+ -p Turned on whenever the real and effective user ids do not match.
+ Disables processing of the $ENV file and importing of shell
+ functions. Turning this option off causes the effective uid and
+ gid to be set to the real uid and gid.
+ -t Exit after reading and executing one command.
+ -u Treat unset variables as an error when substituting.
+ -v Print shell input lines as they are read.
+ -x Print commands and their arguments as they are executed.
#if defined (BRACE_EXPANSION)
- -B the shell will perform brace expansion
+ -B the shell will perform brace expansion
#endif /* BRACE_EXPANSION */
- -C If set, disallow existing regular files to be overwritten
- by redirection of output.
- -E If set, the ERR trap is inherited by shell functions.
+ -C If set, disallow existing regular files to be overwritten
+ by redirection of output.
+ -E If set, the ERR trap is inherited by shell functions.
#if defined (BANG_HISTORY)
- -H Enable ! style history substitution. This flag is on
- by default when the shell is interactive.
+ -H Enable ! style history substitution. This flag is on
+ by default when the shell is interactive.
#endif /* BANG_HISTORY */
- -P If set, do not follow symbolic links when executing commands
- such as cd which change the current directory.
- -T If set, the DEBUG trap is inherited by shell functions.
- - Assign any remaining arguments to the positional parameters.
- The -x and -v options are turned off.
+ -P If set, do not follow symbolic links when executing commands
+ such as cd which change the current directory.
+ -T If set, the DEBUG trap is inherited by shell functions.
+ - Assign any remaining arguments to the positional parameters.
+ The -x and -v options are turned off.
Using + rather than - causes these flags to be turned off. The
flags can also be used upon invocation of the shell. The current
set of flags may be found in $-. The remaining n ARGs are positional
parameters and are assigned, in order, to $1, $2, .. $n. If no
ARGs are given, all shell variables are printed.
+
+Exit Status:
+Returns success unless an invalid option is given.
$END
typedef int setopt_set_func_t __P((int, char *));
@@ -161,13 +169,13 @@ static int get_edit_mode __P((char *));
static int bash_set_history __P((int, char *));
#endif
-static char *on = "on";
-static char *off = "off";
+static const char * const on = "on";
+static const char * const off = "off";
/* A struct used to match long options for set -o to the corresponding
option letter or internal variable. The functions can be called to
dynamically generate values. */
-struct {
+const struct {
char *name;
int letter;
int *variable;
@@ -189,7 +197,7 @@ struct {
{ "histexpand", 'H', (int *)NULL, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
#endif /* BANG_HISTORY */
#if defined (HISTORY)
- { "history", '\0', &remember_on_history, bash_set_history, (setopt_get_func_t *)NULL },
+ { "history", '\0', &enable_history_list, bash_set_history, (setopt_get_func_t *)NULL },
#endif
{ "ignoreeof", '\0', &ignoreeof, set_ignoreeof, (setopt_get_func_t *)NULL },
{ "interactive-comments", '\0', &interactive_comments, (setopt_set_func_t *)NULL, (setopt_get_func_t *)NULL },
@@ -381,13 +389,17 @@ bash_set_history (on_or_off, option_name)
{
if (on_or_off == FLAG_ON)
{
+ enable_history_list = 1;
bash_history_enable ();
if (history_lines_this_session == 0)
load_history ();
}
else
- bash_history_disable ();
- return (1 - remember_on_history);
+ {
+ enable_history_list = 0;
+ bash_history_disable ();
+ }
+ return (1 - enable_history_list);
}
#endif
@@ -422,7 +434,7 @@ set_minus_o_option (on_or_off, option_name)
}
sh_invalidoptname (option_name);
- return (EXECUTION_FAILURE);
+ return (EX_USAGE);
}
static void
@@ -545,7 +557,7 @@ initialize_shell_options (no_shellopts)
/* set up any shell options we may have inherited. */
if (var && imported_p (var))
{
- temp = (array_p (var)) ? (char *)NULL : savestring (value_cell (var));
+ temp = (array_p (var) || assoc_p (var)) ? (char *)NULL : savestring (value_cell (var));
if (temp)
{
parse_shellopts (temp);
@@ -565,7 +577,7 @@ void
reset_shell_options ()
{
#if defined (HISTORY)
- remember_on_history = 1;
+ remember_on_history = enable_history_list = 1;
#endif
ignoreeof = 0;
}
@@ -577,17 +589,18 @@ int
set_builtin (list)
WORD_LIST *list;
{
- int on_or_off, flag_name, force_assignment, opts_changed;
+ int on_or_off, flag_name, force_assignment, opts_changed, rv, r;
register char *arg;
char s[3];
if (list == 0)
{
print_all_shell_variables ();
- return (EXECUTION_SUCCESS);
+ return (sh_chkwrite (EXECUTION_SUCCESS));
}
/* Check validity of flag arguments. */
+ rv = EXECUTION_SUCCESS;
reset_internal_getopt ();
while ((flag_name = internal_getopt (list, optflags)) != -1)
{
@@ -650,6 +663,7 @@ set_builtin (list)
if (opt == 0)
{
list_minus_o_opts (-1, (on_or_off == '+'));
+ rv = sh_chkwrite (rv);
continue;
}
@@ -664,10 +678,10 @@ set_builtin (list)
list = list->next; /* Skip over option name. */
opts_changed = 1;
- if (set_minus_o_option (on_or_off, option_name) != EXECUTION_SUCCESS)
+ if ((r = set_minus_o_option (on_or_off, option_name)) != EXECUTION_SUCCESS)
{
set_shellopts ();
- return (EXECUTION_FAILURE);
+ return (r);
}
}
else if (change_flag (flag_name, on_or_off) == FLAG_ERROR)
@@ -696,17 +710,27 @@ set_builtin (list)
/* Set up new value of $SHELLOPTS */
if (opts_changed)
set_shellopts ();
- return (EXECUTION_SUCCESS);
+ return (rv);
}
$BUILTIN unset
$FUNCTION unset_builtin
$SHORT_DOC unset [-f] [-v] [name ...]
-For each NAME, remove the corresponding variable or function. Given
-the `-v', unset will only act on variables. Given the `-f' flag,
-unset will only act on functions. With neither flag, unset first
-tries to unset a variable, and if that fails, then tries to unset a
-function. Some variables cannot be unset; also see readonly.
+Unset values and attributes of shell variables and functions.
+
+For each NAME, remove the corresponding variable or function.
+
+Options:
+ -f treat each NAME as a shell function
+ -v treat each NAME as a shell variable
+
+Without options, unset first tries to unset a variable, and if that fails,
+tries to unset a function.
+
+Some variables cannot be unset; also see `readonly'.
+
+Exit Status:
+Returns success unless an invalid option is given or a NAME is read-only.
$END
#define NEXT_VARIABLE() any_failed++; list = list->next; continue;
@@ -794,7 +818,7 @@ unset_builtin (list)
#if defined (ARRAY_VARS)
if (var && unset_array)
{
- if (array_p (var) == 0)
+ if (array_p (var) == 0 && assoc_p (var) == 0)
{
builtin_error (_("%s: not an array variable"), name);
NEXT_VARIABLE ();
diff --git a/builtins/setattr.def b/builtins/setattr.def
index 28102bc..8b4cdf7 100644
--- a/builtins/setattr.def
+++ b/builtins/setattr.def
@@ -1,23 +1,22 @@
This file is setattr.def, from which is created setattr.c.
It implements the builtins "export" and "readonly", in Bash.
-Copyright (C) 1987-2004 Free Software Foundation, Inc.
+Copyright (C) 1987-2009 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 2, or (at your option) any later
-version.
+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.
+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; see the file COPYING. If not, write to the Free Software
-Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
+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
@@ -52,14 +51,21 @@ extern int declare_builtin __P((WORD_LIST *));
$BUILTIN export
$FUNCTION export_builtin
-$SHORT_DOC export [-nf] [name[=value] ...] or export -p
-NAMEs are marked for automatic export to the environment of
-subsequently executed commands. If the -f option is given,
-the NAMEs refer to functions. If no NAMEs are given, or if `-p'
-is given, a list of all names that are exported in this shell is
-printed. An argument of `-n' says to remove the export property
-from subsequent NAMEs. An argument of `--' disables further option
-processing.
+$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
@@ -77,13 +83,22 @@ export_builtin (list)
$BUILTIN readonly
$FUNCTION readonly_builtin
$SHORT_DOC readonly [-af] [name[=value] ...] or readonly -p
-The given NAMEs are marked readonly and the values of these NAMEs may
-not be changed by subsequent assignment. If the -f option is given,
-then functions corresponding to the NAMEs are so marked. If no
-arguments are given, or if `-p' is given, a list of all readonly names
-is printed. The `-a' option means to treat each NAME as
-an array variable. An argument of `--' disables further option
-processing.
+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 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 readonly. Given an
@@ -96,7 +111,7 @@ readonly_builtin (list)
}
#if defined (ARRAY_VARS)
-# define ATTROPTS "afnp"
+# define ATTROPTS "aAfnp"
#else
# define ATTROPTS "fnp"
#endif
@@ -110,7 +125,8 @@ set_or_show_attributes (list, attribute, nodefs)
int attribute, nodefs;
{
register SHELL_VAR *var;
- int assign, undo, functions_only, arrays_only, any_failed, assign_error, opt;
+ int assign, undo, any_failed, assign_error, opt;
+ int functions_only, arrays_only, assoc_only;
int aflags;
char *name;
#if defined (ARRAY_VARS)
@@ -118,7 +134,8 @@ set_or_show_attributes (list, attribute, nodefs)
WORD_DESC *w;
#endif
- undo = functions_only = arrays_only = any_failed = assign_error = 0;
+ 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)
@@ -133,8 +150,11 @@ set_or_show_attributes (list, attribute, nodefs)
break;
#if defined (ARRAY_VARS)
case 'a':
- arrays_only = 1;
- break;
+ arrays_only = 1;
+ break;
+ case 'A':
+ assoc_only = 1;
+ break;
#endif
case 'p':
break;
@@ -206,11 +226,11 @@ set_or_show_attributes (list, attribute, nodefs)
#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)
+ if (arrays_only || assoc_only)
{
tlist = list->next;
list->next = (WORD_LIST *)NULL;
- w = make_word ("-ra");
+ w = arrays_only ? make_word ("-ra") : make_word ("-rA");
nlist = make_word_list (w, list);
opt = declare_builtin (nlist);
if (opt != EXECUTION_SUCCESS)
@@ -257,6 +277,12 @@ set_or_show_attributes (list, attribute, nodefs)
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)
@@ -266,9 +292,15 @@ set_or_show_attributes (list, attribute, nodefs)
#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);
+ {
+ show_var_attributes (var, READONLY_OR_EXPORT, nodefs);
+ if (any_failed = sh_chkwrite (any_failed))
+ break;
+ }
}
free (variable_list);
}
@@ -279,6 +311,30 @@ set_or_show_attributes (list, attribute, nodefs)
: 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'.
@@ -290,7 +346,7 @@ show_var_attributes (var, pattr, nodefs)
SHELL_VAR *var;
int pattr, nodefs;
{
- char flags[8], *x;
+ char flags[16], *x;
int i;
i = 0;
@@ -301,6 +357,9 @@ show_var_attributes (var, pattr, nodefs)
#if defined (ARRAY_VARS)
if (array_p (var))
flags[i++] = 'a';
+
+ if (assoc_p (var))
+ flags[i++] = 'A';
#endif
if (function_p (var))
@@ -317,12 +376,24 @@ show_var_attributes (var, pattr, nodefs)
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))
@@ -336,7 +407,7 @@ show_var_attributes (var, pattr, nodefs)
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), 1));
+ 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' */
@@ -350,8 +421,10 @@ show_var_attributes (var, pattr, nodefs)
printf ("%s ", this_command_name);
#if defined (ARRAY_VARS)
- if (array_p (var))
+ 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
@@ -359,7 +432,7 @@ show_var_attributes (var, pattr, nodefs)
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), 1));
+ printf ("%s\n", named_function_string (var->name, function_cell (var), FUNC_MULTILINE|FUNC_EXTERNAL));
else if (invisible_p (var))
printf ("%s\n", var->name);
else
diff --git a/builtins/shift.def b/builtins/shift.def
index e20b4d5..3213086 100644
--- a/builtins/shift.def
+++ b/builtins/shift.def
@@ -1,23 +1,22 @@
This file is shift.def, from which is created shift.c.
It implements the builtin "shift" in Bash.
-Copyright (C) 1987-2003 Free Software Foundation, Inc.
+Copyright (C) 1987-2009 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 2, or (at your option) any later
-version.
+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.
+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; see the file COPYING. If not, write to the Free Software
-Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
+You should have received a copy of the GNU General Public License
+along with Bash. If not, see <http://www.gnu.org/licenses/>.
$PRODUCES shift.c
@@ -39,8 +38,13 @@ $PRODUCES shift.c
$BUILTIN shift
$FUNCTION shift_builtin
$SHORT_DOC shift [n]
-The positional parameters from $N+1 ... are renamed to $1 ... If N is
+Shift positional parameters.
+
+Rename the positional parameters $N+1,$N+2 ... to $1,$2 ... If N is
not given, it is assumed to be 1.
+
+Exit Status:
+Returns success unless N is negative or greater than $#.
$END
int print_shift_error;
@@ -57,7 +61,8 @@ shift_builtin (list)
register int count;
WORD_LIST *temp;
- times = get_numeric_arg (list, 0);
+ if (get_numeric_arg (list, 0, &times) == 0)
+ return (EXECUTION_FAILURE);
if (times == 0)
return (EXECUTION_SUCCESS);
diff --git a/builtins/shopt.def b/builtins/shopt.def
index ae100ac..68c7245 100644
--- a/builtins/shopt.def
+++ b/builtins/shopt.def
@@ -1,37 +1,44 @@
This file is shopt.def, from which is created shopt.c.
It implements the Bash `shopt' builtin.
-Copyright (C) 1994-2005 Free Software Foundation, Inc.
+Copyright (C) 1994-2009 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 2, or (at your option) any later
-version.
+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.
+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; see the file COPYING. If not, write to the Free Software
-Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
+You should have received a copy of the GNU General Public License
+along with Bash. If not, see <http://www.gnu.org/licenses/>.
$PRODUCES shopt.c
$BUILTIN shopt
$FUNCTION shopt_builtin
-$SHORT_DOC shopt [-pqsu] [-o long-option] optname [optname...]
-Toggle the values of variables controlling optional behavior.
-The -s flag means to enable (set) each OPTNAME; the -u flag
-unsets each OPTNAME. The -q flag suppresses output; the exit
-status indicates whether each OPTNAME is set or unset. The -o
-option restricts the OPTNAMEs to those defined for use with
-`set -o'. With no options, or with the -p option, a list of all
-settable options is displayed, with an indication of whether or
-not each is set.
+$SHORT_DOC shopt [-pqsu] [-o] [optname ...]
+Set and unset shell options.
+
+Change the setting of each shell option OPTNAME. Without any option
+arguments, list all shell options with an indication of whether or not each
+is set.
+
+Options:
+ -o restrict OPTNAMEs to those defined for use with `set -o'
+ -p print each shell option with an indication of its status
+ -q suppress output
+ -s enable (set) each OPTNAME
+ -u disable (unset) each OPTNAME
+
+Exit Status:
+Returns success if OPTNAME is enabled; fails if an invalid option is
+given or OPTNAME is disabled.
$END
#include <config.h>
@@ -45,6 +52,8 @@ $END
#include <stdio.h>
+#include "version.h"
+
#include "../bashintl.h"
#include "../shell.h"
@@ -52,6 +61,10 @@ $END
#include "common.h"
#include "bashgetopt.h"
+#if defined (HISTORY)
+# include "../bashhist.h"
+#endif
+
#define UNSETOPT 0
#define SETOPT 1
@@ -68,20 +81,20 @@ extern int glob_ignore_case, match_ignore_case;
extern int hup_on_exit;
extern int xpg_echo;
extern int gnu_error_format;
+extern int check_jobs_at_exit;
+extern int autocd;
+extern int glob_star;
#if defined (EXTENDED_GLOB)
extern int extended_glob;
#endif
-#if defined (HISTORY)
-extern int literal_history, command_oriented_history;
-extern int force_append_history;
-#endif
-
#if defined (READLINE)
extern int hist_verify, history_reediting, perform_hostname_completion;
extern int no_empty_command_completion;
extern int force_fignore;
+extern int dircomplete_spelling;
+
extern int enable_hostname_completion __P((int));
#endif
@@ -99,28 +112,43 @@ extern int debugging_mode;
static void shopt_error __P((char *));
-static int set_shellopts_after_change __P((int));
+static int set_shellopts_after_change __P((char *, int));
+static int shopt_enable_hostname_completion __P((char *, int));
+static int set_compatibility_level __P((char *, int));
#if defined (RESTRICTED_SHELL)
-static int set_restricted_shell __P((int));
+static int set_restricted_shell __P((char *, int));
#endif
static int shopt_login_shell;
+static int shopt_compat31;
+static int shopt_compat32;
+static int shopt_compat40;
-typedef int shopt_set_func_t __P((int));
+typedef int shopt_set_func_t __P((char *, int));
static struct {
char *name;
int *value;
shopt_set_func_t *set_func;
} shopt_vars[] = {
+ { "autocd", &autocd, (shopt_set_func_t *)NULL },
{ "cdable_vars", &cdable_vars, (shopt_set_func_t *)NULL },
{ "cdspell", &cdspelling, (shopt_set_func_t *)NULL },
{ "checkhash", &check_hashed_filenames, (shopt_set_func_t *)NULL },
+#if defined (JOB_CONTROL)
+ { "checkjobs", &check_jobs_at_exit, (shopt_set_func_t *)NULL },
+#endif
{ "checkwinsize", &check_window_size, (shopt_set_func_t *)NULL },
#if defined (HISTORY)
{ "cmdhist", &command_oriented_history, (shopt_set_func_t *)NULL },
#endif
+ { "compat31", &shopt_compat31, set_compatibility_level },
+ { "compat32", &shopt_compat32, set_compatibility_level },
+ { "compat40", &shopt_compat40, set_compatibility_level },
+#if defined (READLINE)
+ { "dirspell", &dircomplete_spelling, (shopt_set_func_t *)NULL },
+#endif
{ "dotglob", &glob_dot_filenames, (shopt_set_func_t *)NULL },
{ "execfail", &no_exit_on_failed_exec, (shopt_set_func_t *)NULL },
{ "expand_aliases", &expand_aliases, (shopt_set_func_t *)NULL },
@@ -135,6 +163,7 @@ static struct {
#if defined (READLINE)
{ "force_fignore", &force_fignore, (shopt_set_func_t *)NULL },
#endif
+ { "globstar", &glob_star, (shopt_set_func_t *)NULL },
{ "gnu_errfmt", &gnu_error_format, (shopt_set_func_t *)NULL },
#if defined (HISTORY)
{ "histappend", &force_append_history, (shopt_set_func_t *)NULL },
@@ -142,7 +171,7 @@ static struct {
#if defined (READLINE)
{ "histreedit", &history_reediting, (shopt_set_func_t *)NULL },
{ "histverify", &hist_verify, (shopt_set_func_t *)NULL },
- { "hostcomplete", &perform_hostname_completion, enable_hostname_completion },
+ { "hostcomplete", &perform_hostname_completion, shopt_enable_hostname_completion },
#endif
{ "huponexit", &hup_on_exit, (shopt_set_func_t *)NULL },
{ "interactive_comments", &interactive_comments, set_shellopts_after_change },
@@ -170,8 +199,12 @@ static struct {
{ (char *)0, (int *)0, (shopt_set_func_t *)NULL }
};
-static char *on = "on";
-static char *off = "off";
+#define N_SHOPT_OPTIONS (sizeof (shopt_vars) / sizeof (shopt_vars[0]))
+
+#define GET_SHOPT_OPTION_VALUE(i) (*shopt_vars[i].value)
+
+static const char * const on = "on";
+static const char * const off = "off";
static int find_shopt __P((char *));
static int toggle_shopts __P((int, WORD_LIST *, int));
@@ -313,9 +346,11 @@ toggle_shopts (mode, list, quiet)
{
*shopt_vars[ind].value = mode; /* 1 for set, 0 for unset */
if (shopt_vars[ind].set_func)
- (*shopt_vars[ind].set_func) (mode);
+ (*shopt_vars[ind].set_func) (shopt_vars[ind].name, mode);
}
}
+
+ set_bashopts ();
return (rval);
}
@@ -348,7 +383,7 @@ list_shopts (list, flags)
if ((flags & QFLAG) == 0)
print_shopt (shopt_vars[i].name, val, flags);
}
- return (EXECUTION_SUCCESS);
+ return (sh_chkwrite (EXECUTION_SUCCESS));
}
for (l = list, rval = EXECUTION_SUCCESS; l; l = l->next)
@@ -367,7 +402,7 @@ list_shopts (list, flags)
print_shopt (l->word->word, val, flags);
}
- return (rval);
+ return (sh_chkwrite (rval));
}
static int
@@ -382,7 +417,7 @@ list_some_shopts (mode, flags)
if (((flags & QFLAG) == 0) && mode == val)
print_shopt (shopt_vars[i].name, val, flags);
}
- return (EXECUTION_SUCCESS);
+ return (sh_chkwrite (EXECUTION_SUCCESS));
}
static int
@@ -397,7 +432,7 @@ list_shopt_o_options (list, flags)
{
if ((flags & QFLAG) == 0)
list_minus_o_opts (-1, (flags & PFLAG));
- return (EXECUTION_SUCCESS);
+ return (sh_chkwrite (EXECUTION_SUCCESS));
}
for (l = list, rval = EXECUTION_SUCCESS; l; l = l->next)
@@ -419,7 +454,7 @@ list_shopt_o_options (list, flags)
printf (OPTFMT, l->word->word, val ? on : off);
}
}
- return (rval);
+ return (sh_chkwrite (rval));
}
static int
@@ -428,7 +463,7 @@ list_some_o_options (mode, flags)
{
if ((flags & QFLAG) == 0)
list_minus_o_opts (mode, (flags & PFLAG));
- return (EXECUTION_SUCCESS);
+ return (sh_chkwrite (EXECUTION_SUCCESS));
}
static int
@@ -452,18 +487,56 @@ set_shopt_o_options (mode, list, quiet)
/* If we set or unset interactive_comments with shopt, make sure the
change is reflected in $SHELLOPTS. */
static int
-set_shellopts_after_change (mode)
+set_shellopts_after_change (option_name, mode)
+ char *option_name;
int mode;
{
set_shellopts ();
return (0);
}
+static int
+shopt_enable_hostname_completion (option_name, mode)
+ char *option_name;
+ int mode;
+{
+ return (enable_hostname_completion (mode));
+}
+
+static int
+set_compatibility_level (option_name, mode)
+ char *option_name;
+ int mode;
+{
+ /* Need to change logic here as we add more compatibility levels */
+
+ /* First, check option_name so we can turn off other compat options when
+ one is set. */
+ if (mode && option_name[6] == '3' && option_name[7] == '1')
+ shopt_compat32 = shopt_compat40 = 0;
+ else if (mode && option_name[6] == '3' && option_name[7] == '2')
+ shopt_compat31 = shopt_compat40 = 0;
+ else if (mode && option_name[6] == '4' && option_name[7] == '0')
+ shopt_compat31 = shopt_compat32 = 0;
+
+ /* Then set shell_compatibility_level based on what remains */
+ if (shopt_compat31)
+ shell_compatibility_level = 31;
+ else if (shopt_compat32)
+ shell_compatibility_level = 32;
+ else if (shopt_compat40)
+ shell_compatibility_level = 40;
+ else
+ shell_compatibility_level = DEFAULT_COMPAT_LEVEL;
+ return 0;
+}
+
#if defined (RESTRICTED_SHELL)
/* Don't allow the value of restricted_shell to be modified. */
static int
-set_restricted_shell (mode)
+set_restricted_shell (option_name, mode)
+ char *option_name;
int mode;
{
static int save_restricted = -1;
@@ -478,7 +551,8 @@ set_restricted_shell (mode)
/* Not static so shell.c can call it to initialize shopt_login_shell */
int
-set_login_shell (mode)
+set_login_shell (option_name, mode)
+ char *option_name;
int mode;
{
shopt_login_shell = login_shell != 0;
@@ -536,5 +610,106 @@ shopt_listopt (name, reusable)
}
print_shopt (name, *shopt_vars[i].value, reusable ? PFLAG : 0);
- return (EXECUTION_SUCCESS);
+ return (sh_chkwrite (EXECUTION_SUCCESS));
+}
+
+void
+set_bashopts ()
+{
+ char *value;
+ char tflag[N_SHOPT_OPTIONS];
+ int vsize, i, vptr, *ip, exported;
+ SHELL_VAR *v;
+
+ for (vsize = i = 0; shopt_vars[i].name; i++)
+ {
+ tflag[i] = 0;
+ if (GET_SHOPT_OPTION_VALUE (i))
+ {
+ vsize += strlen (shopt_vars[i].name) + 1;
+ tflag[i] = 1;
+ }
+ }
+
+ value = (char *)xmalloc (vsize + 1);
+
+ for (i = vptr = 0; shopt_vars[i].name; i++)
+ {
+ if (tflag[i])
+ {
+ strcpy (value + vptr, shopt_vars[i].name);
+ vptr += strlen (shopt_vars[i].name);
+ value[vptr++] = ':';
+ }
+ }
+
+ if (vptr)
+ vptr--; /* cut off trailing colon */
+ value[vptr] = '\0';
+
+ v = find_variable ("BASHOPTS");
+
+ /* Turn off the read-only attribute so we can bind the new value, and
+ note whether or not the variable was exported. */
+ if (v)
+ {
+ VUNSETATTR (v, att_readonly);
+ exported = exported_p (v);
+ }
+ else
+ exported = 0;
+
+ v = bind_variable ("BASHOPTS", value, 0);
+
+ /* Turn the read-only attribute back on, and turn off the export attribute
+ if it was set implicitly by mark_modified_vars and SHELLOPTS was not
+ exported before we bound the new value. */
+ VSETATTR (v, att_readonly);
+ if (mark_modified_vars && exported == 0 && exported_p (v))
+ VUNSETATTR (v, att_exported);
+
+ free (value);
+}
+
+void
+parse_bashopts (value)
+ char *value;
+{
+ char *vname;
+ int vptr, ind;
+
+ vptr = 0;
+ while (vname = extract_colon_unit (value, &vptr))
+ {
+ ind = find_shopt (vname);
+ if (ind >= 0)
+ *shopt_vars[ind].value = 1;
+ free (vname);
+ }
+}
+
+void
+initialize_bashopts (no_bashopts)
+ int no_bashopts;
+{
+ char *temp;
+ SHELL_VAR *var;
+
+ if (no_bashopts == 0)
+ {
+ var = find_variable ("BASHOPTS");
+ /* set up any shell options we may have inherited. */
+ if (var && imported_p (var))
+ {
+ temp = (array_p (var) || assoc_p (var)) ? (char *)NULL : savestring (value_cell (var));
+ if (temp)
+ {
+ parse_bashopts (temp);
+ free (temp);
+ }
+ }
+ }
+
+ /* Set up the $BASHOPTS variable. */
+ set_bashopts ();
}
diff --git a/builtins/source.def b/builtins/source.def
index 9576f09..72627db 100644
--- a/builtins/source.def
+++ b/builtins/source.def
@@ -1,44 +1,55 @@
This file is source.def, from which is created source.c.
It implements the builtins "." and "source" in Bash.
-Copyright (C) 1987-2003 Free Software Foundation, Inc.
+Copyright (C) 1987-2009 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 2, or (at your option) any later
-version.
+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.
+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; see the file COPYING. If not, write to the Free Software
-Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
+You should have received a copy of the GNU General Public License
+along with Bash. If not, see <http://www.gnu.org/licenses/>.
$PRODUCES source.c
$BUILTIN source
$FUNCTION source_builtin
$SHORT_DOC source filename [arguments]
-Read and execute commands from FILENAME and return. The pathnames
-in $PATH are used to find the directory containing FILENAME. If any
-ARGUMENTS are supplied, they become the positional parameters when
-FILENAME is executed.
+Execute commands from a file in the current shell.
+
+Read and execute commands from FILENAME in the current shell. The
+entries in $PATH are used to find the directory containing FILENAME.
+If any ARGUMENTS are supplied, they become the positional parameters
+when FILENAME is executed.
+
+Exit Status:
+Returns the status of the last command executed in FILENAME; fails if
+FILENAME cannot be read.
$END
+
$BUILTIN .
$DOCNAME dot
$FUNCTION source_builtin
$SHORT_DOC . filename [arguments]
-Read and execute commands from FILENAME and return. The pathnames
-in $PATH are used to find the directory containing FILENAME. If any
-ARGUMENTS are supplied, they become the positional parameters when
-FILENAME is executed.
+Execute commands from a file in the current shell.
+
+Read and execute commands from FILENAME in the current shell. The
+entries in $PATH are used to find the directory containing FILENAME.
+If any ARGUMENTS are supplied, they become the positional parameters
+when FILENAME is executed.
+
+Exit Status:
+Returns the status of the last command executed in FILENAME; fails if
+FILENAME cannot be read.
$END
-/* source.c - Implements the `.' and `source' builtins. */
#include <config.h>
@@ -68,6 +79,8 @@ $END
extern int errno;
#endif /* !errno */
+extern int posixly_correct;
+
static void maybe_pop_dollar_vars __P((void));
/* If non-zero, `.' uses $PATH to look up the script to be sourced. */
@@ -126,7 +139,12 @@ source_builtin (list)
#endif
filename = (char *)NULL;
- if (source_uses_path)
+ /* XXX -- should this be absolute_pathname? */
+ if (posixly_correct && strchr (list->word->word, '/'))
+ filename = savestring (list->word->word);
+ else if (absolute_pathname (list->word->word))
+ filename = savestring (list->word->word);
+ else if (source_uses_path)
filename = find_path_file (list->word->word);
if (filename == 0)
{
diff --git a/builtins/suspend.def b/builtins/suspend.def
index ea86ae2..8711e68 100644
--- a/builtins/suspend.def
+++ b/builtins/suspend.def
@@ -1,23 +1,22 @@
This file is suspend.def, from which is created suspend.c.
It implements the builtin "suspend" in Bash.
-Copyright (C) 1987-2003 Free Software Foundation, Inc.
+Copyright (C) 1987-2009 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 2, or (at your option) any later
-version.
+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.
+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; see the file COPYING. If not, write to the Free Software
-Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
+You should have received a copy of the GNU General Public License
+along with Bash. If not, see <http://www.gnu.org/licenses/>.
$PRODUCES suspend.c
@@ -25,9 +24,16 @@ $BUILTIN suspend
$DEPENDS_ON JOB_CONTROL
$FUNCTION suspend_builtin
$SHORT_DOC suspend [-f]
-Suspend the execution of this shell until it receives a SIGCONT
-signal. The `-f' if specified says not to complain about this
-being a login shell if it is; just suspend anyway.
+Suspend shell execution.
+
+Suspend the execution of this shell until it receives a SIGCONT signal.
+Unless forced, login shells cannot be suspended.
+
+Options:
+ -f force the suspend, even if the shell is a login shell
+
+Exit Status:
+Returns success unless job control is not enabled or an error occurs.
$END
#include <config.h>
diff --git a/builtins/test.def b/builtins/test.def
index 44f48a4..4adff93 100644
--- a/builtins/test.def
+++ b/builtins/test.def
@@ -1,29 +1,30 @@
This file is test.def, from which is created test.c.
It implements the builtin "test" in Bash.
-Copyright (C) 1987-2002 Free Software Foundation, Inc.
+Copyright (C) 1987-2009 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 2, or (at your option) any later
-version.
+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.
+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; see the file COPYING. If not, write to the Free Software
-Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
+You should have received a copy of the GNU General Public License
+along with Bash. If not, see <http://www.gnu.org/licenses/>.
$PRODUCES test.c
$BUILTIN test
$FUNCTION test_builtin
$SHORT_DOC test [expr]
+Evaluate conditional expression.
+
Exits with a status of 0 (true) or 1 (false) depending on
the evaluation of EXPR. Expressions may be unary or binary. Unary
expressions are often used to examine the status of a file. There
@@ -31,27 +32,27 @@ are string operators as well, and numeric comparison operators.
File operators:
- -a FILE True if file exists.
- -b FILE True if file is block special.
- -c FILE True if file is character special.
- -d FILE True if file is a directory.
- -e FILE True if file exists.
- -f FILE True if file exists and is a regular file.
- -g FILE True if file is set-group-id.
- -h FILE True if file is a symbolic link.
- -L FILE True if file is a symbolic link.
- -k FILE True if file has its `sticky' bit set.
- -p FILE True if file is a named pipe.
- -r FILE True if file is readable by you.
- -s FILE True if file exists and is not empty.
- -S FILE True if file is a socket.
- -t FD True if FD is opened on a terminal.
- -u FILE True if the file is set-user-id.
- -w FILE True if the file is writable by you.
- -x FILE True if the file is executable by you.
- -O FILE True if the file is effectively owned by you.
- -G FILE True if the file is effectively owned by your group.
- -N FILE True if the file has been modified since it was last read.
+ -a FILE True if file exists.
+ -b FILE True if file is block special.
+ -c FILE True if file is character special.
+ -d FILE True if file is a directory.
+ -e FILE True if file exists.
+ -f FILE True if file exists and is a regular file.
+ -g FILE True if file is set-group-id.
+ -h FILE True if file is a symbolic link.
+ -L FILE True if file is a symbolic link.
+ -k FILE True if file has its `sticky' bit set.
+ -p FILE True if file is a named pipe.
+ -r FILE True if file is readable by you.
+ -s FILE True if file exists and is not empty.
+ -S FILE True if file is a socket.
+ -t FD True if FD is opened on a terminal.
+ -u FILE True if the file is set-user-id.
+ -w FILE True if the file is writable by you.
+ -x FILE True if the file is executable by you.
+ -O FILE True if the file is effectively owned by you.
+ -G FILE True if the file is effectively owned by your group.
+ -N FILE True if the file has been modified since it was last read.
FILE1 -nt FILE2 True if file1 is newer than file2 (according to
modification date).
@@ -60,49 +61,49 @@ File operators:
FILE1 -ef FILE2 True if file1 is a hard link to file2.
-All file operators except -h and -L are acting on the target of a symbolic
-link, not on the symlink itself, if FILE is a symbolic link.
-
String operators:
- -z STRING True if string is empty.
+ -z STRING True if string is empty.
- -n STRING
- STRING True if string is not empty.
+ -n STRING
+ STRING True if string is not empty.
- STRING1 = STRING2
- True if the strings are equal.
- STRING1 != STRING2
- True if the strings are not equal.
- STRING1 < STRING2
- True if STRING1 sorts before STRING2 lexicographically.
- STRING1 > STRING2
- True if STRING1 sorts after STRING2 lexicographically.
+ STRING1 = STRING2
+ True if the strings are equal.
+ STRING1 != STRING2
+ True if the strings are not equal.
+ STRING1 < STRING2
+ True if STRING1 sorts before STRING2 lexicographically.
+ STRING1 > STRING2
+ True if STRING1 sorts after STRING2 lexicographically.
Other operators:
- -o OPTION True if the shell option OPTION is enabled.
- ! EXPR True if expr is false.
- EXPR1 -a EXPR2 True if both expr1 AND expr2 are true.
- EXPR1 -o EXPR2 True if either expr1 OR expr2 is true.
+ -o OPTION True if the shell option OPTION is enabled.
+ ! EXPR True if expr is false.
+ EXPR1 -a EXPR2 True if both expr1 AND expr2 are true.
+ EXPR1 -o EXPR2 True if either expr1 OR expr2 is true.
- arg1 OP arg2 Arithmetic tests. OP is one of -eq, -ne,
- -lt, -le, -gt, or -ge.
+ arg1 OP arg2 Arithmetic tests. OP is one of -eq, -ne,
+ -lt, -le, -gt, or -ge.
Arithmetic binary operators return true if ARG1 is equal, not-equal,
less-than, less-than-or-equal, greater-than, or greater-than-or-equal
than ARG2.
-See the bash manual page bash(1) for the handling of parameters (i.e.
-missing parameters).
+Exit Status:
+Returns success if EXPR evaluates to true; fails if EXPR evaluates to
+false or an invalid argument is given.
$END
$BUILTIN [
$DOCNAME test_bracket
$FUNCTION test_builtin
$SHORT_DOC [ arg... ]
-This is a synonym for the "test" builtin, but the last
-argument must be a literal `]', to match the opening `['.
+Evaluate conditional expression.
+
+This is a synonym for the "test" builtin, but the last argument must
+be a literal `]', to match the opening `['.
$END
#include <config.h>
@@ -115,6 +116,7 @@ $END
#endif
#include "../bashansi.h"
+#include "../bashintl.h"
#include "../shell.h"
#include "../test.h"
@@ -137,7 +139,7 @@ test_builtin (list)
{
if (this_command_name[0] == '[' && !this_command_name[1])
{
- builtin_error ("missing `]'");
+ builtin_error (_("missing `]'"));
return (EX_BADUSAGE);
}
diff --git a/builtins/times.def b/builtins/times.def
index 22304fc..f31f433 100644
--- a/builtins/times.def
+++ b/builtins/times.def
@@ -1,31 +1,35 @@
This file is times.def, from which is created times.c.
It implements the builtin "times" in Bash.
-Copyright (C) 1987-2002 Free Software Foundation, Inc.
+Copyright (C) 1987-2009 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 2, or (at your option) any later
-version.
+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.
+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; see the file COPYING. If not, write to the Free Software
-Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
+You should have received a copy of the GNU General Public License
+along with Bash. If not, see <http://www.gnu.org/licenses/>.
$PRODUCES times.c
$BUILTIN times
$FUNCTION times_builtin
$SHORT_DOC times
-Print the accumulated user and system times for processes run from
-the shell.
+Display process times.
+
+Prints the accumulated user and system times for the shell and all of its
+child processes.
+
+Exit Status:
+Always succeeds.
$END
#include <config.h>
@@ -111,5 +115,5 @@ times_builtin (list)
# endif /* HAVE_TIMES */
#endif /* !HAVE_TIMES */
- return (EXECUTION_SUCCESS);
+ return (sh_chkwrite (EXECUTION_SUCCESS));
}
diff --git a/builtins/trap.def b/builtins/trap.def
index 2735791..a8da71d 100644
--- a/builtins/trap.def
+++ b/builtins/trap.def
@@ -1,43 +1,55 @@
This file is trap.def, from which is created trap.c.
It implements the builtin "trap" in Bash.
-Copyright (C) 1987-2006 Free Software Foundation, Inc.
+Copyright (C) 1987-2009 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 2, or (at your option) any later
-version.
+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.
+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; see the file COPYING. If not, write to the Free Software
-Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
+You should have received a copy of the GNU General Public License
+along with Bash. If not, see <http://www.gnu.org/licenses/>.
$PRODUCES trap.c
$BUILTIN trap
$FUNCTION trap_builtin
-$SHORT_DOC trap [-lp] [arg signal_spec ...]
-The command ARG is to be read and executed when the shell receives
+$SHORT_DOC trap [-lp] [[arg] signal_spec ...]
+Trap signals and other events.
+
+Defines and activates handlers to be run when the shell receives signals
+or other conditions.
+
+ARG is a command to be read and executed when the shell receives the
signal(s) SIGNAL_SPEC. If ARG is absent (and a single SIGNAL_SPEC
is supplied) or `-', each specified signal is reset to its original
value. If ARG is the null string each SIGNAL_SPEC is ignored by the
-shell and by the commands it invokes. If a SIGNAL_SPEC is EXIT (0)
-the command ARG is executed on exit from the shell. If a SIGNAL_SPEC
-is DEBUG, ARG is executed after every simple command. If the`-p' option
-is supplied then the trap commands associated with each SIGNAL_SPEC are
-displayed. If no arguments are supplied or if only `-p' is given, trap
-prints the list of commands associated with each signal. Each SIGNAL_SPEC
-is either a signal name in <signal.h> or a signal number. Signal names
-are case insensitive and the SIG prefix is optional. `trap -l' prints
-a list of signal names and their corresponding numbers. Note that a
-signal can be sent to the shell with "kill -signal $$".
+shell and by the commands it invokes.
+
+If a SIGNAL_SPEC is EXIT (0) ARG is executed on exit from the shell. If
+a SIGNAL_SPEC is DEBUG, ARG is executed before every simple command.
+
+If no arguments are supplied, trap prints the list of commands associated
+with each signal.
+
+Options:
+ -l print a list of signal names and their corresponding numbers
+ -p display the trap commands associated with each SIGNAL_SPEC
+
+Each SIGNAL_SPEC is either a signal name in <signal.h> or a signal number.
+Signal names are case insensitive and the SIG prefix is optional. A
+signal may be sent to the shell with "kill -signal $$".
+
+Exit Status:
+Returns success unless a SIGSPEC is invalid or an invalid option is given.
$END
#include <config.h>
@@ -112,9 +124,9 @@ trap_builtin (list)
opt = DSIG_NOCASE|DSIG_SIGPREFIX; /* flags for decode_signal */
if (list_signal_names)
- return (display_signal_list ((WORD_LIST *)NULL, 1));
+ return (sh_chkwrite (display_signal_list ((WORD_LIST *)NULL, 1)));
else if (display || list == 0)
- return (display_traps (list));
+ return (sh_chkwrite (display_traps (list)));
else
{
char *first_arg;
diff --git a/builtins/type.def b/builtins/type.def
index d03ccb2..ee341bb 100644
--- a/builtins/type.def
+++ b/builtins/type.def
@@ -1,50 +1,53 @@
This file is type.def, from which is created type.c.
It implements the builtin "type" in Bash.
-Copyright (C) 1987-2002 Free Software Foundation, Inc.
+Copyright (C) 1987-2009 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 2, or (at your option) any later
-version.
+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.
+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; see the file COPYING. If not, write to the Free Software
-Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
+You should have received a copy of the GNU General Public License
+along with Bash. If not, see <http://www.gnu.org/licenses/>.
$PRODUCES type.c
$BUILTIN type
$FUNCTION type_builtin
$SHORT_DOC type [-afptP] name [name ...]
+Display information about command type.
+
For each NAME, indicate how it would be interpreted if used as a
command name.
-If the -t option is used, `type' outputs a single word which is one of
-`alias', `keyword', `function', `builtin', `file' or `', if NAME is an
-alias, shell reserved word, shell function, shell builtin, disk file,
-or unfound, respectively.
-
-If the -p flag is used, `type' either returns the name of the disk
-file that would be executed, or nothing if `type -t NAME' would not
-return `file'.
-
-If the -a flag is used, `type' displays all of the places that contain
-an executable named `file'. This includes aliases, builtins, and
-functions, if and only if the -p flag is not also used.
-
-The -f flag suppresses shell function lookup.
-
-The -P flag forces a PATH search for each NAME, even if it is an alias,
-builtin, or function, and returns the name of the disk file that would
-be executed.
+Options:
+ -a display all locations containing an executable named NAME;
+ includes aliases, builtins, and functions, if and only if
+ the `-p' option is not also used
+ -f suppress shell function lookup
+ -P force a PATH search for each NAME, even if it is an alias,
+ builtin, or function, and returns the name of the disk file
+ that would be executed
+ -p returns either the name of the disk file that would be executed,
+ or nothing if `type -t NAME' would not return `file'.
+ -t output a single word which is one of `alias', `keyword',
+ `function', `builtin', `file' or `', if NAME is an alias, shell
+ reserved word, shell function, shell builtin, disk file, or not
+ found, respectively
+
+Arguments:
+ NAME Command name to be interpreted.
+
+Exit Status:
+Returns success if all of the NAMEs are found; fails if any are not found.
$END
#include <config.h>
@@ -108,14 +111,14 @@ int
type_builtin (list)
WORD_LIST *list;
{
- int dflags, successful_finds, opt;
+ int dflags, any_failed, opt;
WORD_LIST *this;
if (list == 0)
return (EXECUTION_SUCCESS);
dflags = CDESC_SHORTDESC; /* default */
- successful_finds = 0;
+ any_failed = 0;
/* Handle the obsolescent `-type', `-path', and `-all' by prescanning
the arguments and converting those options to the form that
@@ -181,13 +184,12 @@ type_builtin (list)
if (!found && (dflags & (CDESC_PATH_ONLY|CDESC_TYPE)) == 0)
sh_notfound (list->word->word);
- successful_finds += found;
+ any_failed += found == 0;
list = list->next;
}
- fflush (stdout);
-
- return ((successful_finds != 0) ? EXECUTION_SUCCESS : EXECUTION_FAILURE);
+ opt = (any_failed == 0) ? EXECUTION_SUCCESS : EXECUTION_FAILURE;
+ return (sh_chkwrite (opt));
}
/*
@@ -267,18 +269,14 @@ describe_command (command, dflags)
puts ("function");
else if (dflags & CDESC_SHORTDESC)
{
-#define PRETTY_PRINT_FUNC 1
char *result;
printf (_("%s is a function\n"), command);
/* We're blowing away THE_PRINTED_COMMAND here... */
- result = named_function_string (command,
- (COMMAND *) function_cell (func),
- PRETTY_PRINT_FUNC);
+ result = named_function_string (command, function_cell (func), FUNC_MULTILINE|FUNC_EXTERNAL);
printf ("%s\n", result);
-#undef PRETTY_PRINT_FUNC
}
else if (dflags & CDESC_REUSABLE)
printf ("%s\n", command);
@@ -390,7 +388,7 @@ describe_command (command, dflags)
if (dflags & CDESC_TYPE)
puts ("file");
else if (dflags & CDESC_SHORTDESC)
- printf ("%s is %s\n", command, full_path);
+ printf (_("%s is %s\n"), command, full_path);
else if (dflags & (CDESC_REUSABLE|CDESC_PATH_ONLY))
printf ("%s\n", full_path);
diff --git a/builtins/ulimit.def b/builtins/ulimit.def
index 2d2e7b2..7c1e256 100644
--- a/builtins/ulimit.def
+++ b/builtins/ulimit.def
@@ -1,62 +1,68 @@
This file is ulimit.def, from which is created ulimit.c.
It implements the builtin "ulimit" in Bash.
-Copyright (C) 1987-2005 Free Software Foundation, Inc.
+Copyright (C) 1987-2009 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 2, or (at your option) any later
-version.
+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.
+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; see the file COPYING. If not, write to the Free Software
-Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
+You should have received a copy of the GNU General Public License
+along with Bash. If not, see <http://www.gnu.org/licenses/>.
$PRODUCES ulimit.c
$BUILTIN ulimit
$FUNCTION ulimit_builtin
$DEPENDS_ON !_MINIX
-$SHORT_DOC ulimit [-SHacdfilmnpqstuvx] [limit]
-Ulimit provides control over the resources available to processes
-started by the shell, on systems that allow such control. If an
-option is given, it is interpreted as follows:
-
- -S use the `soft' resource limit
- -H use the `hard' resource limit
- -a all current limits are reported
- -c the maximum size of core files created
- -d the maximum size of a process's data segment
- -e the maximum scheduling priority (`nice')
- -f the maximum size of files written by the shell and its children
- -i the maximum number of pending signals
- -l the maximum size a process may lock into memory
- -m the maximum resident set size
- -n the maximum number of open file descriptors
- -p the pipe buffer size
- -q the maximum number of bytes in POSIX message queues
- -r the maximum real-time scheduling priority
- -s the maximum stack size
- -t the maximum amount of cpu time in seconds
- -u the maximum number of user processes
- -v the size of virtual memory
- -x the maximum number of file locks
-
-If LIMIT is given, it is the new value of the specified resource;
-the special LIMIT values `soft', `hard', and `unlimited' stand for
-the current soft limit, the current hard limit, and no limit, respectively.
-Otherwise, the current value of the specified resource is printed.
-If no option is given, then -f is assumed. Values are in 1024-byte
-increments, except for -t, which is in seconds, -p, which is in
-increments of 512 bytes, and -u, which is an unscaled number of
-processes.
+$SHORT_DOC ulimit [-SHacdefilmnpqrstuvx] [limit]
+Modify shell resource limits.
+
+Provides control over the resources available to the shell and processes
+it creates, on systems that allow such control.
+
+Options:
+ -S use the `soft' resource limit
+ -H use the `hard' resource limit
+ -a all current limits are reported
+ -b the socket buffer size
+ -c the maximum size of core files created
+ -d the maximum size of a process's data segment
+ -e the maximum scheduling priority (`nice')
+ -f the maximum size of files written by the shell and its children
+ -i the maximum number of pending signals
+ -l the maximum size a process may lock into memory
+ -m the maximum resident set size
+ -n the maximum number of open file descriptors
+ -p the pipe buffer size
+ -q the maximum number of bytes in POSIX message queues
+ -r the maximum real-time scheduling priority
+ -s the maximum stack size
+ -t the maximum amount of cpu time in seconds
+ -u the maximum number of user processes
+ -v the size of virtual memory
+ -x the maximum number of file locks
+
+If LIMIT is given, it is the new value of the specified resource; the
+special LIMIT values `soft', `hard', and `unlimited' stand for the
+current soft limit, the current hard limit, and no limit, respectively.
+Otherwise, the current value of the specified resource is printed. If
+no option is given, then -f is assumed.
+
+Values are in 1024-byte increments, except for -t, which is in seconds,
+-p, which is in increments of 512 bytes, and -u, which is an unscaled
+number of processes.
+
+Exit Status:
+Returns success unless an invalid option is supplied or an error occurs.
$END
#if !defined (_MINIX)
@@ -98,7 +104,7 @@ extern int errno;
# if defined (HPUX) && defined (RLIMIT_NEEDS_KERNEL)
# undef _KERNEL
# endif
-#else
+#elif defined (HAVE_SYS_TIMES_H)
# include <sys/times.h>
#endif
@@ -172,6 +178,14 @@ extern int errno;
#define LIMIT_HARD 0x01
#define LIMIT_SOFT 0x02
+/* "Blocks" are defined as 512 bytes when in Posix mode and 1024 bytes
+ otherwise. */
+#define POSIXBLK -2
+
+#define BLOCKSIZE(x) (((x) == POSIXBLK) ? (posixly_correct ? 512 : 1024) : (x))
+
+extern int posixly_correct;
+
static int _findlim __P((int));
static int ulimit_internal __P((int, char *, int, int));
@@ -193,13 +207,19 @@ typedef struct {
int option; /* The ulimit option for this limit. */
int parameter; /* Parameter to pass to get_limit (). */
int block_factor; /* Blocking factor for specific limit. */
- char *description; /* Descriptive string to output. */
- char *units; /* scale */
+ const char * const description; /* Descriptive string to output. */
+ const char * const units; /* scale */
} RESOURCE_LIMITS;
static RESOURCE_LIMITS limits[] = {
+#ifdef RLIMIT_PTHREAD
+ { 'T', RLIMIT_PTHREAD, 1, "number of threads", (char *)NULL },
+#endif
+#ifdef RLIMIT_SBSIZE
+ { 'b', RLIMIT_SBSIZE, 1, "socket buffer size", "bytes" },
+#endif
#ifdef RLIMIT_CORE
- { 'c', RLIMIT_CORE, 1024, "core file size", "blocks" },
+ { 'c', RLIMIT_CORE, POSIXBLK, "core file size", "blocks" },
#endif
#ifdef RLIMIT_DATA
{ 'd', RLIMIT_DATA, 1024, "data seg size", "kbytes" },
@@ -207,7 +227,7 @@ static RESOURCE_LIMITS limits[] = {
#ifdef RLIMIT_NICE
{ 'e', RLIMIT_NICE, 1, "scheduling priority", (char *)NULL },
#endif
- { 'f', RLIMIT_FILESIZE, 1024, "file size", "blocks" },
+ { 'f', RLIMIT_FILESIZE, POSIXBLK, "file size", "blocks" },
#ifdef RLIMIT_SIGPENDING
{ 'i', RLIMIT_SIGPENDING, 1, "pending signals", (char *)NULL },
#endif
@@ -356,7 +376,7 @@ ulimit_builtin (list)
}
#endif
print_all_limits (mode == 0 ? LIMIT_SOFT : mode);
- return (EXECUTION_SUCCESS);
+ return (sh_chkwrite (EXECUTION_SUCCESS));
}
/* default is `ulimit -f' */
@@ -425,12 +445,12 @@ ulimit_internal (cmd, cmdarg, mode, multiple)
else if (all_digits (cmdarg))
{
limit = string_to_rlimtype (cmdarg);
- block_factor = limits[limind].block_factor;
+ block_factor = BLOCKSIZE(limits[limind].block_factor);
real_limit = limit * block_factor;
if ((real_limit / block_factor) != limit)
{
- sh_erange (cmdarg, "limit");
+ sh_erange (cmdarg, _("limit"));
return (EXECUTION_FAILURE);
}
}
@@ -687,7 +707,9 @@ printone (limind, curlim, pdesc)
int pdesc;
{
char unitstr[64];
+ int factor;
+ factor = BLOCKSIZE(limits[limind].block_factor);
if (pdesc)
{
if (limits[limind].units)
@@ -704,7 +726,7 @@ printone (limind, curlim, pdesc)
else if (curlim == RLIM_SAVED_CUR)
puts ("soft");
else
- print_rlimtype ((curlim / limits[limind].block_factor), 1);
+ print_rlimtype ((curlim / factor), 1);
}
/* Set all limits to NEWLIM. NEWLIM currently must be RLIM_INFINITY, which
@@ -740,7 +762,7 @@ set_all_limits (mode, newlim)
for (retval = i = 0; limits[i].option > 0; i++)
if (set_limit (i, newlim, mode) < 0)
{
- builtin_error ("%s: cannot modify limit: %s", limits[i].description,
+ builtin_error (_("%s: cannot modify limit: %s"), limits[i].description,
strerror (errno));
retval = 1;
}
diff --git a/builtins/umask.def b/builtins/umask.def
index 489ca33..289a0f5 100644
--- a/builtins/umask.def
+++ b/builtins/umask.def
@@ -1,36 +1,42 @@
This file is umask.def, from which is created umask.c.
It implements the builtin "umask" in Bash.
-Copyright (C) 1987-2004 Free Software Foundation, Inc.
+Copyright (C) 1987-2009 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 2, or (at your option) any later
-version.
+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.
+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; see the file COPYING. If not, write to the Free Software
-Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
+You should have received a copy of the GNU General Public License
+along with Bash. If not, see <http://www.gnu.org/licenses/>.
$PRODUCES umask.c
$BUILTIN umask
$FUNCTION umask_builtin
$SHORT_DOC umask [-p] [-S] [mode]
-The user file-creation mask is set to MODE. If MODE is omitted, or if
-`-S' is supplied, the current value of the mask is printed. The `-S'
-option makes the output symbolic; otherwise an octal number is output.
-If `-p' is supplied, and MODE is omitted, the output is in a form
-that may be used as input. If MODE begins with a digit, it is
-interpreted as an octal number, otherwise it is a symbolic mode string
-like that accepted by chmod(1).
+Display or set file mode mask.
+
+Sets the user file-creation mask to MODE. If MODE is omitted, prints
+the current value of the mask.
+
+If MODE begins with a digit, it is interpreted as an octal number;
+otherwise it is a symbolic mode string like that accepted by chmod(1).
+
+Options:
+ -p if MODE is omitted, output in a form that may be reused as input
+ -S makes the output symbolic; otherwise an octal number is output
+
+Exit Status:
+Returns success unless MODE is invalid or an invalid option is given.
$END
#include <config.h>
@@ -137,8 +143,7 @@ umask_builtin (list)
printf ("%04lo\n", (unsigned long)umask_arg);
}
- fflush (stdout);
- return (EXECUTION_SUCCESS);
+ return (sh_chkwrite (EXECUTION_SUCCESS));
}
/* Print the umask in a symbolic form. In the output, a letter is
diff --git a/builtins/wait.def b/builtins/wait.def
index a309595..0206926 100644
--- a/builtins/wait.def
+++ b/builtins/wait.def
@@ -1,44 +1,54 @@
This file is wait.def, from which is created wait.c.
It implements the builtin "wait" in Bash.
-Copyright (C) 1987-2005 Free Software Foundation, Inc.
+Copyright (C) 1987-2009 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 2, or (at your option) any later
-version.
+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.
+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; see the file COPYING. If not, write to the Free Software
-Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
+You should have received a copy of the GNU General Public License
+along with Bash. If not, see <http://www.gnu.org/licenses/>.
$BUILTIN wait
$FUNCTION wait_builtin
$DEPENDS_ON JOB_CONTROL
$PRODUCES wait.c
-$SHORT_DOC wait [n]
-Wait for the specified process and report its termination status. If
-N is not given, all currently active child processes are waited for,
-and the return code is zero. N may be a process ID or a job
-specification; if a job spec is given, all processes in the job's
-pipeline are waited for.
+$SHORT_DOC wait [id]
+Wait for job completion and return exit status.
+
+Waits for the process identified by ID, which may be a process ID or a
+job specification, and reports its termination status. If ID is not
+given, waits for all currently active child processes, and the return
+status is zero. If ID is a a job specification, waits for all processes
+in the job's pipeline.
+
+Exit Status:
+Returns the status of ID; fails if ID is invalid or an invalid option is
+given.
$END
$BUILTIN wait
$FUNCTION wait_builtin
$DEPENDS_ON !JOB_CONTROL
-$SHORT_DOC wait [n]
-Wait for the specified process and report its termination status. If
-N is not given, all currently active child processes are waited for,
-and the return code is zero. N is a process ID; if it is not given,
-all child processes of the shell are waited for.
+$SHORT_DOC wait [pid]
+Wait for process completion and return exit status.
+
+Waits for the specified process and reports its termination status. If
+PID is not given, all currently active child processes are waited for,
+and the return code is zero. PID must be a process ID.
+
+Exit Status:
+Returns the status of ID; fails if ID is invalid or an invalid option is
+given.
$END
#include <config.h>