Bash-4.2 distribution sources and documentation

This commit is contained in:
Chet Ramey 2011-11-22 19:11:26 -05:00
parent 30d188c293
commit 495aee441b
341 changed files with 108751 additions and 36060 deletions

385
CHANGES
View File

@ -1,3 +1,388 @@
This document details the changes between this version, bash-4.2-release,
and the previous version, bash-4.2-rc2.
1. Changes to Bash
a. Fixed a bug that caused some variables to be clobbered by a longjmp,
resulting in stack corruption.
------------------------------------------------------------------------------
This document details the changes between this version, bash-4.2-rc2,
and the previous version, bash-4.2-rc1.
1. Changes to Bash
a. Changes to bash_directory_completion_hook so that it's assigned to the
readline rl_directory_rewrite_hook variable, which modifies the directory
name passed to opendir without modifying the directory name the user
typed.
b. Fixed bug in select builtin that caused it to not terminate correctly if
the read timed out due to $TMOUT.
c. Fixed a problem that resulted in non-repeatable sequences of random
numbers when RANDOM=0.
------------------------------------------------------------------------------
This document details the changes between this version, bash-4.2-rc1,
and the previous version, bash-4.2-beta.
1. Changes to Bash
a. Fixed a bug that caused some redirection errors to leak file descriptors.
b. Fixed a bug that caused unary `+' and `-' arithmetic operators to have a
higher precedence than unary `!' and `~'.
c. Fixed a bug that caused simple commands in a pipeline to affect the exit
status ($?) seen by subsequent pipeline commands.
d. A number of cygwin-specific changes to avoid the use of text-mode files
and file access, and to make sure that \r is handled correctly.
e. Fixed a bug that caused the read builtin to not return failure if an
attempt is made to assign to a readonly variable.
f. Fixed a bug that caused some builtin usage messages to not be translated.
g. Fixed a bug that caused the getopts builtin to not return failure if an
attempt is made to assign to a readonly variable. Now it returns 2.
h. Fixed the cd and pwd builtins to return failure if PWD is readonly and
cannot be assigned to.
i. Added code to check the return value of access(2) on Solaris systems,
since it returns success for executable tests (e.g., `test -x') when
run by root, even if the file permissions don't allow execution.
2. Changes to Readline
a. Fixed a bug that caused directory names in words to be completed to not
be dequoted correctly.
3. New Features in Bash
4. New Features in Readline
------------------------------------------------------------------------------
This document details the changes between this version, bash-4.2-beta,
and the previous version, bash-4.2-alpha.
1. Changes to Bash
a. Fixed a bug that caused the \W prompt string escape to not add a closing
NULL.
b. Fixed a bug that caused partially-quoted words that were not subject to
word splitting to retained quoted NULLs.
c. Added considerable efficiency speedups when pattern matching in multibyte
locales by skipping multibyte character functions where possible.
d. Added considerable speedups to variable expansion when in multibyte locales.
e. Fixed a bug that caused the expansion of $* when there are no positional
parameters to cause the shell to dump core when used in a pattern
matching context.
f. Fixed a bug that caused variable expansions preceding regular builtins to
not change the shell environment during their execution.
2. Changes to Readline
a. Fixed a bug that made an explicit argument of 0 to yank-last-arg behave
as if it were a negative argument.
------------------------------------------------------------------------------
This document details the changes between this version, bash-4.2-alpha,
and the previous version, bash-4.1-release.
1. Changes to Bash
a. Fixed a bug in the parser when processing alias expansions containing
quoted newlines.
b. Fixed a memory leak in associative array expansion.
c. Fixed a bug that caused quoted here-strings to be requoted when printed.
d. Fixed a bug in arithmetic expansion that caused the index in an array
expansion to be evaluated twice under certain circumstances.
e. Fixed several bugs with the expansion and display of variables that have
been given attributes but not values and are technically unset.
f. Fixed a bug that caused core dumps when using filename completion that
expands to a filename containing a globbing character.
g. Fixed a bug that caused assignment statements preceding a special builtin
when running in Posix mode to not persist after the builtin completed
when the special builtin was executed in a shell function without any
local variables.
h. Fixed a bug that caused a command to remain in the hash table even after
`hash command' did not find anything if there was already an existing
hashed pathname.
i. Fixed several bugs caused by executing unsafe functions from a signal
handler in the cases where a signal handler is executed immediately
rather than setting a flag for later execution.
j. Fixed a bug that caused some internal flag variables to be set
incorrectly if `read -t' timed out.
k. Fixed a Posix compatibility issue by making sure that a backslash escaping
a `}' within a double-quoted ${...} parameter expansion is removed as part
of the parameter expansion.
l. Fixed a bug that caused execution of a trap to overwrite PIPESTATUS.
m. Fixed a bug that caused here documents to not be displayed correctly
when attached to commands inside compound commands.
n. Fixed a bug that caused the printf builtin to use the wrong precision
when using the `*' modifier.
o. Fixed a bug that caused an arriving SIGCHLD to interrupt output functions
like those invoked by echo or printf.
p. Changed to use a more robust mechanism than eaccess(2) when test is
checking filenames for execution permission.
q. Fixed a bug that caused spurious semicolons to be added into the command
history in certain cases.
r. Fixed a bug that caused the shell to free non-allocated memory when
unsetting element 0 of an associative array after it was assigned
implicitly.
s. Fixed a bug that could cause the shell to dump core if using the `v'
vi editing command on a multi-line command.
t. Fixed a bug that left FIFOs opened by process substitutions open long
enough to potentially cause file descriptor exhaustion when running a
shell function or shell builtin.
u. Fixed a bug that caused the history expansion functions to not recognize
process substitution or extended glob patterns as single words.
v. Fixed a bug that caused restricted shells to set a restricted command's
exit status incorrectly.
w. Fixed a bug that caused bash to ignore the wrong set of filenames when
completing a command using the `complete-filename' readline command.
x. Fixed a bug that caused a -PID argument following a -s sig or -n sig to
not be interpreted as a signal specification.
y. Changed posix-mode behavior of a parse error in a `.' script or `eval'
command to exit the shell under Posix-specified conditions. Previous
versions printed a warning.
z. Fixed a bug in \W prompt expansion that resulted in incorrect expansion
in the event of overlapping strings.
aa. Fixed a bug that caused the := parameter expansion operator to return the
wrong value as the result of the expansion.
bb. When in Posix mode, a single quote is not treated specially in a
double-quoted ${...} expansion, unless the expansion operator is
# or % or the non-Posix `//', `^', and `,'. In particular, it does
not define a new quoting context. This is from Posix interpretation 221.
cc. Fixed a bug that inadvertently allowed program names containing slashes
to be entered into the command hash table.
dd. Fixed a bug that caused the select builtin to incorrectly compute the
display width of the arguments in the presence of multibyte characters.
ee. Fixed a bug that caused bash to not change the xtrace file descriptor if
BASH_XTRACEFD was found in the shell environment at startup.
ff. Fixed a memory leak in the pattern removal parameter expansion.
gg. Fixed a bug that caused SIGINT to fail to interrupt a nested loop if the
loop was in a pipeline.
hh. Fixed a problem in $(...) parsing that caused the parser to add an extra
space to a here-document delimiter if the first word contained a `/'.
ii. Fixed a bug that caused functions defined with the `function' reserved
word to require braces around the function body.
jj. Fixed a bug that caused bash to dump core when a variable expansion being
used as an array subscript failed.
kk. Fixed a bug that caused bash to dump core if the case-modification
expansions were used on a variable with a null value.
ll. Fixed a bug that caused partially-quoted strings to be split incorrectly
if a variable with a null value was expanded within double quotes.
mm. The pattern substitution word expansion has been sped up dramatically
when running in a locale with multibyte characters.
nn. Fixed a bug that caused history -a to not write the correct lines to
the history file if all the new lines in the history list were added
since the last time the history file was read or written.
oo. Fixed a bug that caused completion of a word with an unclosed `` command
substitution to set the prompt incorrectly.
pp. Fixed a bug that caused extended globbing patterns in $HISTIGNORE or
$GLOBIGNORE to be incorrectly scanned.
qq. Fixed a bug caused by closing file descriptors 3-20 on shell startup. The
shell now sets them to close-on-exec.
rr. Fixed a bug that caused the exit status of `exec file' to be set incorrectly
if `file' was a directory.
ss. Fixed a bug in the `.' builtin to make a non-interactive posix-mode shell
exit if the file argument to `.' is not found. Prefixing exec with
`command' makes the shell not exit. Posix requires this behavior.
tt. Fixed a bug that caused `sh -c 'command exec; exit 1' to hang.
uu. Fixed a bug in $(...) command substitution parsing that caused the shell
to treat backslash-newline incorrectly when parsing a comment.
vv. Fixed bug that caused brace expansion sequence generation to misbehave
when supplied integers greater than 2**31 - 1.
ww. Fixed a bug that caused failure to save file descriptors for redirections
to corrupt shell file descriptors.
xx. Fixed a bug that caused bash-forward-shellword to not correctly handle
quoted strings.
2. Changes to Readline
a. Fixed a bug that caused the unconverted filename to be added to the list of
completions when the application specified filename conversion functions.
b. Fixed a bug that caused the wrong filename to be passed to opendir when the
application has specified a filename dequoting function.
c. Fixed a bug when repeating a character search in vi mode in the case where
there was no search to repeat.
d. When show-all-if-ambiguous is set, the completion routines no longer insert
a common match prefix that is shorter than the text being completed.
e. The full set of vi editing commands may now be used in callback mode.
f. Fixed a bug that caused readline to not update its idea of the terminal
dimensions while running in `no-echo' mode.
h. Fixed a bug that caused readline to dump core if an application called
rl_prep_terminal without setting rl_instream.
i. Fixed a bug that caused meta-prefixed characters bound to incremental
search forward or backward to not be recognized if they were typed
subsequently.
j. The incremental search code treats key sequences that map to the same
functions as (default) ^G, ^W, and ^Y as equivalent to those characters.
k. Fixed a bug in menu-complete that caused it to misbehave with large
negative argument.
l. Fixed a bug that caused vi-mode yank-last-arg to ring the bell when invoked
at the end of the line.
3. New Features in Bash
a. `exec -a foo' now sets $0 to `foo' in an executable shell script without a
leading #!.
b. Subshells begun to execute command substitutions or run shell functions or
builtins in subshells do not reset trap strings until a new trap is
specified. This allows $(trap) to display the caller's traps and the
trap strings to persist until a new trap is set.
c. `trap -p' will now show signals ignored at shell startup, though their
disposition still cannot be modified.
d. $'...', echo, and printf understand \uXXXX and \UXXXXXXXX escape sequences.
e. declare/typeset has a new `-g' option, which creates variables in the
global scope even when run in a shell function.
f. test/[/[[ have a new -v variable unary operator, which returns success if
`variable' has been set.
g. Posix parsing changes to allow `! time command' and multiple consecutive
instances of `!' (which toggle) and `time' (which have no cumulative
effect).
h. Posix change to allow `time' as a command by itself to print the elapsed
user, system, and real times for the shell and its children.
j. $((...)) is always parsed as an arithmetic expansion first, instead of as
a potential nested command substitution, as Posix requires.
k. A new FUNCNEST variable to allow the user to control the maximum shell
function nesting (recursive execution) level.
l. The mapfile builtin now supplies a third argument to the callback command:
the line about to be assigned to the supplied array index.
m. The printf builtin has a new %(fmt)T specifier, which allows time values
to use strftime-like formatting.
n. There is a new `compat41' shell option.
o. The cd builtin has a new Posix-mandated `-e' option.
p. Negative subscripts to indexed arrays, previously errors, now are treated
as offsets from the maximum assigned index + 1.
q. Negative length specifications in the ${var:offset:length} expansion,
previously errors, are now treated as offsets from the end of the variable.
r. Parsing change to allow `time -p --'.
s. Posix-mode parsing change to not recognize `time' as a keyword if the
following token begins with a `-'. This means no more Posix-mode
`time -p'. Posix interpretation 267.
t. There is a new `lastpipe' shell option that runs the last command of a
pipeline in the current shell context. The lastpipe option has no
effect if job control is enabled.
u. History expansion no longer expands the `$!' variable expansion.
v. Posix mode shells no longer exit if a variable assignment error occurs
with an assignment preceding a command that is not a special builtin.
w. Non-interactive mode shells exit if -u is enabled and an attempt is made
to use an unset variable with the % or # expansions, the `//', `^', or
`,' expansions, or the parameter length expansion.
x. Posix-mode shells use the argument passed to `.' as-is if a $PATH search
fails, effectively searching the current directory. Posix-2008 change.
4. New Features in Readline
a. The history library does not try to write the history filename in the
current directory if $HOME is unset. This closes a potential security
problem if the application does not specify a history filename.
b. New bindable variable `completion-display-width' to set the number of
columns used when displaying completions.
c. New bindable variable `completion-case-map' to cause case-insensitive
completion to treat `-' and `_' as identical.
d. There are new bindable vi-mode command names to avoid readline's case-
insensitive matching not allowing them to be bound separately.
e. New bindable variable `menu-complete-display-prefix' causes the menu
completion code to display the common prefix of the possible completions
before cycling through the list, instead of after.
------------------------------------------------------------------------------
This document details the changes between this version, bash-4.1-rc,
and the previous version, bash-4.1-beta.

48
COMPAT
View File

@ -295,7 +295,8 @@ version and versions 2.0 and above.
37. Bash-4.0 now allows SIGCHLD to interrupt the wait builtin, as Posix
specifies, so the SIGCHLD trap is no longer always invoked once per
exiting child if you are using `wait' to wait for all children.
exiting child if you are using `wait' to wait for all children. As
of bash-4.2, this is the status quo only when in posix mode.
38. Since bash-4.0 now follows Posix rules for finding the closing delimiter
of a $() command substitution, it will not behave as previous versions
@ -330,35 +331,58 @@ version and versions 2.0 and above.
44. Bash-4.1 uses the current locale when comparing strings using the < and
> operators to the `[[' command. This can be reverted to the previous
behavior by setting one of the `compatNN' shopt options.
behavior (ASCII collating and strcmp(3)) by setting one of the
`compatNN' shopt options, where NN is less than 41.
45. Command substitutions now remove the caller's trap strings when trap is
run to set a new trap in the subshell. Previous to bash-4.2, the old
trap strings persisted even though the actual signal handlers were reset.
46. When in Posix mode, a single quote is not treated specially in a
double-quoted ${...} expansion, unless the expansion operator is
# or % or the new `//', `^', or `,' expansions. In particular, it
does not define a new quoting context. This is from Posix interpretation
221.
47. Posix mode shells no longer exit if a variable assignment error occurs
with an assignment preceding a command that is not a special builtin.
Shell Compatibility Level
=========================
Bash-4.0 introduced the concept of a `shell compatibility level', specified
as a set of options to the shopt builtin (compat31, compat32, compat40 at
this writing). There is only one current compatibility level -- each
option is mutually exclusive. This list does not mention behavior that is
standard for a particular version (e.g., setting compat32 means that quoting
the rhs of the regexp matching operator quotes special regexp characters in
the word, which is default behavior in bash-3.2 and above).
as a set of options to the shopt builtin (compat31, compat32, compat40, and
compat41 at this writing). There is only one current compatibility level --
each option is mutually exclusive. This list does not mention behavior
that is standard for a particular version (e.g., setting compat32 means that
quoting the rhs of the regexp matching operator quotes special regexp
characters in the word, which is default behavior in bash-3.2 and above).
compat31 set
- the < and > operators to the [[ command do not consider the current
locale when comparing strings
locale when comparing strings; they use ASCII ordering
- quoting the rhs of the regexp matching operator (=~) has no
special effect
compat32 set
- the < and > operators to the [[ command do not consider the current
locale when comparing strings
locale when comparing strings; they use ASCII ordering
compat40 set
- the < and > operators to the [[ command do not consider the current
locale when comparing strings
locale when comparing strings; they use ASCII ordering
- interrupting a command list such as "a ; b ; c" causes the execution
of the entire list to be aborted
of the entire list to be aborted (in versions before bash-4.0,
interrupting one command in a list caused the next to be executed)
compat41 set
- interrupting a command list such as "a ; b ; c" causes the execution
of the entire list to be aborted (in versions before bash-4.0,
interrupting one command in a list caused the next to be executed)
- when in posix mode, single quotes in the `word' portion of a
double-quoted parameter expansion define a new quoting context and
are treated specially
-------------------------------------------------------------------------------
Copying and distribution of this file, with or without modification,

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
/* sigs - print signal dispositions for a process */
/* Copyright (C) 1990-2009 Free Software Foundation, Inc.
/* Copyright (C) 1990-2010 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@ -21,7 +21,7 @@
#include <signal.h>
#include <stdio.h>
extern char *sys_siglist[];
extern const char * const sys_siglist[];
typedef void sighandler();

1
ChangeLog Symbolic link
View File

@ -0,0 +1 @@
CWRU/changelog

View File

@ -376,8 +376,8 @@ does not provide the necessary support.
The Restricted Shell::, for a description of restricted mode.
`--enable-select'
Include the `select' builtin, which allows the generation of simple
menus (*note Conditional Constructs::).
Include the `select' compound command, which allows the generation
of simple menus (*note Conditional Constructs::).
`--enable-separate-helpfiles'
Use external files for the documentation displayed by the `help'

View File

@ -220,6 +220,7 @@ include/posixselect.h f
include/posixstat.h f
include/posixtime.h f
include/posixwait.h f
include/shmbchar.h f
include/shmbutil.h f
include/shtty.h f
include/stdc.h f
@ -234,6 +235,7 @@ lib/glob/strmatch.h f
lib/glob/glob.c f
lib/glob/glob.h f
lib/glob/glob_loop.c f
lib/glob/gmisc.c f
lib/glob/xmbsrtowcs.c f
lib/glob/collsyms.h f
lib/glob/doc/Makefile f
@ -315,6 +317,7 @@ lib/readline/funmap.c f
lib/readline/keymaps.c f
lib/readline/util.c f
lib/readline/terminal.c f
lib/readline/xfree.c f
lib/readline/xmalloc.c f
lib/readline/search.c f
lib/readline/isearch.c f
@ -382,8 +385,8 @@ lib/sh/Makefile.in f
lib/sh/casemod.c f
lib/sh/clktck.c f
lib/sh/clock.c f
lib/sh/dprintf.c f
lib/sh/eaccess.c f
lib/sh/fdprintf.c f
lib/sh/fmtullong.c f
lib/sh/fmtulong.c f
lib/sh/fmtumax.c f
@ -409,12 +412,14 @@ lib/sh/pathphys.c f
lib/sh/rename.c f
lib/sh/setlinebuf.c f
lib/sh/shmatch.c f
lib/sh/shmbchar.c f
lib/sh/shquote.c f
lib/sh/shtty.c f
lib/sh/snprintf.c f
lib/sh/spell.c f
lib/sh/strcasecmp.c f
lib/sh/strcasestr.c f
lib/sh/strchrnul.c f
lib/sh/strerror.c f
lib/sh/strftime.c f
lib/sh/stringlist.c f
@ -435,8 +440,10 @@ lib/sh/timeval.c f
lib/sh/tmpfile.c f
lib/sh/uconvert.c f
lib/sh/ufuncs.c f
lib/sh/unicode.c f
lib/sh/vprint.c f
lib/sh/wcsdup.c f
lib/sh/wcswidth.c f
lib/sh/winsize.c f
lib/sh/zcatfd.c f
lib/sh/zgetline.c f
@ -515,8 +522,12 @@ po/sv.gmo f
po/sv.po f
po/tr.gmo f
po/tr.po f
po/uk.gmo f
po/uk.po f
po/vi.gmo f
po/vi.po f
po/zh_CN.gmo f
po/zh_CN.po f
po/zh_TW.gmo f
po/zh_TW.po f
po/insert-header.sin f
@ -685,6 +696,7 @@ examples/functions/which f
examples/functions/xalias.bash f
examples/functions/xfind.bash f
examples/scripts/adventure.sh f
examples/scripts/bash-hexdump.sh f
examples/scripts/bcsh.sh f
examples/scripts/cat.sh f
examples/scripts/center f
@ -742,6 +754,8 @@ tests/arith.tests f
tests/arith.right f
tests/arith1.sub f
tests/arith2.sub f
tests/arith3.sub f
tests/arith4.sub f
tests/array.tests f
tests/array.right f
tests/array1.sub f
@ -753,6 +767,7 @@ tests/array6.sub f
tests/array7.sub f
tests/array8.sub f
tests/array9.sub f
tests/array10.sub f
tests/array-at-star f
tests/array2.right f
tests/assoc.tests f
@ -769,6 +784,7 @@ tests/builtins.tests f
tests/builtins.right f
tests/builtins1.sub f
tests/builtins2.sub f
tests/builtins3.sub f
tests/source1.sub f
tests/source2.sub f
tests/source3.sub f
@ -793,6 +809,8 @@ tests/comsub-eof.right f
tests/comsub-posix.tests f
tests/comsub-posix.right f
tests/comsub-posix1.sub f
tests/comsub-posix2.sub f
tests/comsub-posix3.sub f
tests/cond.tests f
tests/cond.right f
tests/cond-regexp.sub f
@ -832,11 +850,13 @@ tests/exec5.sub f
tests/exec6.sub f
tests/exec7.sub f
tests/exec8.sub f
tests/exec9.sub f
tests/exp.tests f
tests/exp.right f
tests/exp1.sub f
tests/exp2.sub f
tests/exp3.sub f
tests/exp4.sub f
tests/extglob.tests f
tests/extglob.right f
tests/extglob1.sub f
@ -849,6 +869,7 @@ tests/func.right f
tests/func1.sub f
tests/func2.sub f
tests/func3.sub f
tests/func4.sub f
tests/getopts.tests f
tests/getopts.right f
tests/getopts1.sub f
@ -885,6 +906,7 @@ tests/input-line.sub f
tests/input.right f
tests/intl.tests f
tests/intl1.sub f
tests/intl2.sub f
tests/intl.right f
tests/iquote.tests f
tests/iquote.right f
@ -896,6 +918,9 @@ tests/jobs2.sub f
tests/jobs3.sub f
tests/jobs4.sub f
tests/jobs.right f
tests/lastpipe.right f
tests/lastpipe.tests f
tests/lastpipe1.sub f
tests/mapfile.data f
tests/mapfile.right f
tests/mapfile.tests f
@ -910,6 +935,7 @@ tests/new-exp4.sub f
tests/new-exp5.sub f
tests/new-exp6.sub f
tests/new-exp7.sub f
tests/new-exp8.sub f
tests/new-exp.right f
tests/nquote.tests f
tests/nquote.right f
@ -926,13 +952,23 @@ tests/nquote5.tests f
tests/nquote5.right f
tests/posix2.tests f
tests/posix2.right f
tests/posixexp.tests f
tests/posixexp.right f
tests/posixexp1.sub f
tests/posixexp2.sub f
tests/posixexp2.tests f
tests/posixexp2.right f
tests/posixpat.tests f
tests/posixpat.right f
tests/posixpipe.tests f
tests/posixpipe.right f
tests/prec.right f
tests/precedence f
tests/printf.tests f
tests/printf.right f
tests/printf1.sub f
tests/printf2.sub f
tests/printf3.sub f
tests/quote.tests f
tests/quote.right f
tests/read.tests f
@ -1005,6 +1041,7 @@ tests/run-intl f
tests/run-iquote f
tests/run-invert f
tests/run-jobs f
tests/run-lastpipe f
tests/run-mapfile f
tests/run-more-exp f
tests/run-new-exp f
@ -1015,7 +1052,10 @@ tests/run-nquote3 f
tests/run-nquote4 f
tests/run-nquote5 f
tests/run-posix2 f
tests/run-posixexp f
tests/run-posixexp2 f
tests/run-posixpat f
tests/run-posixpipe f
tests/run-precedence f
tests/run-printf f
tests/run-quote f
@ -1061,6 +1101,7 @@ tests/type.tests f
tests/type.right f
tests/type1.sub f
tests/type2.sub f
tests/type3.sub f
tests/varenv.right f
tests/varenv.sh f
tests/varenv1.sub f
@ -1074,6 +1115,7 @@ tests/vredir2.sub f
tests/vredir3.sub f
tests/vredir4.sub f
tests/vredir5.sub f
tests/vredir6.sub f
tests/misc/dev-tcp.tests f
tests/misc/perf-script f
tests/misc/perftest f

View File

@ -1,6 +1,6 @@
# Makefile for bash-4.0, version 3.5
# Makefile for bash-4.2, version 4.4
#
# Copyright (C) 1996-2009 Free Software Foundation, Inc.
# Copyright (C) 1996-2010 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
@ -185,7 +185,7 @@ SH_ABSSRC = ${topdir}/${SH_LIBSRC}
SHLIB_SOURCE = ${SH_LIBSRC}/clktck.c ${SH_LIBSRC}/getcwd.c \
${SH_LIBSRC}/getenv.c ${SH_LIBSRC}/oslib.c \
${SH_LIBSRC}/setlinebuf.c \
${SH_LIBSRC}/setlinebuf.c ${SH_LIBSRC}/strchrnul.c \
${SH_LIBSRC}/strcasecmp.c ${SH_LIBSRC}/strerror.c \
${SH_LIBSRC}/strtod.c ${SH_LIBSRC}/strtol.c \
${SH_LIBSRC}/strtoul.c ${SH_LIBSRC}/vprint.c \
@ -212,9 +212,10 @@ SHLIB_SOURCE = ${SH_LIBSRC}/clktck.c ${SH_LIBSRC}/getcwd.c \
${SH_LIBSRC}/zmapfd.c ${SH_LIBSRC}/fpurge.c \
${SH_LIBSRC}/zgetline.c ${SH_LIBSRC}/mbscmp.c \
${SH_LIBSRC}/casemod.c ${SH_LIBSRC}/uconvert.c \
${SH_LIBSRC}/ufuncs.c ${SH_LIBSRC}/fdprintf.c \
${SH_LIBSRC}/ufuncs.c ${SH_LIBSRC}/dprintf.c \
${SH_LIBSRC}/input_avail.c ${SH_LIBSRC}/mbscasecmp.c \
${SH_LIBSRC}/fnxform.c
${SH_LIBSRC}/fnxform.c ${SH_LIBSRC}/unicode.c \
${SH_LIBSRC}/wcswidth.c ${SH_LIBSRC}/shmbchar.c
SHLIB_LIB = -lsh
SHLIB_LIBNAME = libsh.a
@ -318,9 +319,11 @@ GLOB_DEP = $(GLOB_LIBRARY)
GLOB_SOURCE = $(GLOB_LIBSRC)/glob.c $(GLOB_LIBSRC)/strmatch.c \
$(GLOB_LIBSRC)/smatch.c $(GLOB_LIBSRC)/xmbsrtowcs.c \
$(GLOB_LIBSRC)/glob_loop.c $(GLOB_LIBSRC)/sm_loop.c \
$(GLOB_LIBSRC)/gmisc.c \
$(GLOB_LIBSRC)/glob.h $(GLOB_LIBSRC)/strmatch.h
GLOB_OBJ = $(GLOB_LIBDIR)/glob.o $(GLOB_LIBDIR)/strmatch.o \
$(GLOB_LIBDIR)/smatch.o $(GLOB_LIBDIR)/xmbsrtowcs.o
$(GLOB_LIBDIR)/smatch.o $(GLOB_LIBDIR)/xmbsrtowcs.o \
$(GLOB_LIBDIR)/gmisc.o
# The source, object and documentation for the GNU Tilde library.
TILDE_LIBSRC = $(LIBSRC)/tilde
@ -519,7 +522,7 @@ CREATED_SUPPORT = signames.h recho$(EXEEXT) zecho$(EXEEXT) printenv$(EXEEXT) \
mksyntax${EXEEXT} syntax.c $(VERSPROG) $(VERSOBJ) \
buildversion.o mksignames.o signames.o buildsignames.o
CREATED_CONFIGURE = config.h config.cache config.status config.log \
stamp-h po/POTFILES
stamp-h po/POTFILES config.status.lineno
CREATED_MAKEFILES = Makefile builtins/Makefile doc/Makefile \
lib/readline/Makefile lib/glob/Makefile \
lib/sh/Makefile lib/tilde/Makefile lib/malloc/Makefile \
@ -564,7 +567,7 @@ strip: $(Program) .made
lint:
${MAKE} ${MFLAGS} CFLAGS='${GCC_LINT_FLAGS}' .made
version.h: $(SOURCES) config.h Makefile
version.h: $(SOURCES) config.h Makefile patchlevel.h
$(SHELL) $(SUPPORT_SRC)mkversion.sh -b -S ${topdir} -s $(RELSTATUS) -d $(Version) -o newversion.h \
&& mv newversion.h version.h
@ -969,8 +972,8 @@ mailcheck.o: execute_cmd.h mailcheck.h
make_cmd.o: config.h bashtypes.h ${BASHINCDIR}/filecntl.h bashansi.h
make_cmd.o: command.h ${BASHINCDIR}/stdc.h general.h xmalloc.h error.h flags.h make_cmd.h
make_cmd.o: variables.h arrayfunc.h conftypes.h array.h hashlib.h subst.h input.h externs.h
make_cmd.o: jobs.h quit.h siglist.h syntax.h dispose_cmd.h
make_cmd.o: ${BASHINCDIR}/shmbutil.h ${BASHINCDIR}/ocache.h
make_cmd.o: jobs.h quit.h siglist.h syntax.h dispose_cmd.h parser.h
make_cmd.o: ${BASHINCDIR}/shmbutil.h ${BASHINCDIR}/shmbchar.h ${BASHINCDIR}/ocache.h
y.tab.o: config.h bashtypes.h bashansi.h ${BASHINCDIR}/ansi_stdlib.h ${BASHINCDIR}/memalloc.h
y.tab.o: shell.h syntax.h config.h bashjmp.h ${BASHINCDIR}/posixjmp.h command.h ${BASHINCDIR}/stdc.h error.h
y.tab.o: general.h xmalloc.h bashtypes.h variables.h arrayfunc.h conftypes.h array.h hashlib.h
@ -985,7 +988,7 @@ pathexp.o: quit.h ${BASHINCDIR}/maxpath.h unwind_prot.h dispose_cmd.h
pathexp.o: make_cmd.h subst.h sig.h pathnames.h externs.h
pathexp.o: pathexp.h flags.h
pathexp.o: $(GLOB_LIBSRC)/glob.h $(GLOB_LIBSRC)/strmatch.h
pathexp.o: ${BASHINCDIR}/shmbutil.h
pathexp.o: ${BASHINCDIR}/shmbutil.h ${BASHINCDIR}/shmbchar.h
print_cmd.o: config.h bashansi.h ${BASHINCDIR}/ansi_stdlib.h
print_cmd.o: shell.h syntax.h config.h bashjmp.h ${BASHINCDIR}/posixjmp.h command.h ${BASHINCDIR}/stdc.h error.h
print_cmd.o: general.h xmalloc.h bashtypes.h variables.h arrayfunc.h conftypes.h array.h hashlib.h
@ -1022,12 +1025,12 @@ subst.o: config.h bashtypes.h bashansi.h ${BASHINCDIR}/ansi_stdlib.h ${BASHINCDI
subst.o: shell.h syntax.h config.h bashjmp.h ${BASHINCDIR}/posixjmp.h command.h ${BASHINCDIR}/stdc.h error.h
subst.o: general.h xmalloc.h bashtypes.h variables.h arrayfunc.h conftypes.h array.h hashlib.h
subst.o: quit.h ${BASHINCDIR}/maxpath.h unwind_prot.h dispose_cmd.h
subst.o: make_cmd.h subst.h sig.h pathnames.h externs.h
subst.o: make_cmd.h subst.h sig.h pathnames.h externs.h parser.h
subst.o: flags.h jobs.h siglist.h execute_cmd.h ${BASHINCDIR}/filecntl.h trap.h pathexp.h
subst.o: mailcheck.h input.h $(DEFSRC)/getopt.h $(DEFSRC)/common.h
subst.o: bashline.h bashhist.h ${GLOB_LIBSRC}/strmatch.h
subst.o: ${BASHINCDIR}/chartypes.h
subst.o: ${BASHINCDIR}/shmbutil.h
subst.o: ${BASHINCDIR}/shmbutil.h ${BASHINCDIR}/shmbchar.h
subst.o: ${DEFDIR}/builtext.h
test.o: bashtypes.h ${BASHINCDIR}/posixstat.h ${BASHINCDIR}/filecntl.h
test.o: shell.h syntax.h config.h bashjmp.h ${BASHINCDIR}/posixjmp.h command.h ${BASHINCDIR}/stdc.h error.h
@ -1086,7 +1089,7 @@ arrayfunc.o: general.h xmalloc.h bashtypes.h variables.h arrayfunc.h conftypes.h
arrayfunc.o: quit.h ${BASHINCDIR}/maxpath.h unwind_prot.h dispose_cmd.h
arrayfunc.o: make_cmd.h subst.h sig.h pathnames.h externs.h pathexp.h
arrayfunc.o: $(DEFSRC)/common.h
arrayfunc.o: ${BASHINCDIR}/shmbutil.h
arrayfunc.o: ${BASHINCDIR}/shmbutil.h ${BASHINCDIR}/shmbchar.h
assoc.o: config.h bashansi.h ${BASHINCDIR}/ansi_stdlib.h
assoc.o: shell.h syntax.h config.h bashjmp.h ${BASHINCDIR}/posixjmp.h
assoc.o: command.h ${BASHINCDIR}/stdc.h error.h
@ -1100,7 +1103,7 @@ braces.o: shell.h syntax.h config.h bashjmp.h ${BASHINCDIR}/posixjmp.h command.h
braces.o: general.h xmalloc.h bashtypes.h variables.h arrayfunc.h conftypes.h array.h hashlib.h
braces.o: quit.h ${BASHINCDIR}/maxpath.h unwind_prot.h dispose_cmd.h
braces.o: make_cmd.h subst.h sig.h pathnames.h externs.h
braces.o: ${BASHINCDIR}/shmbutil.h
braces.o: ${BASHINCDIR}/shmbutil.h ${BASHINCDIR}/shmbchar.h
alias.o: config.h bashansi.h ${BASHINCDIR}/ansi_stdlib.h command.h ${BASHINCDIR}/stdc.h
alias.o: general.h xmalloc.h bashtypes.h externs.h alias.h
alias.o: pcomplete.h
@ -1184,7 +1187,7 @@ jobs.o: bashintl.h ${LIBINTL_H} $(BASHINCDIR)/gettext.h
mailcheck.o: bashintl.h ${LIBINTL_H} $(BASHINCDIR)/gettext.h
make_cmd.o: bashintl.h ${LIBINTL_H} $(BASHINCDIR)/gettext.h
nojobs.o: bashintl.h ${LIBINTL_H} $(BASHINCDIR)/gettext.h
parse.y: bashintl.h ${LIBINTL_H} $(BASHINCDIR)/gettext.h
y.tab.o: bashintl.h ${LIBINTL_H} $(BASHINCDIR)/gettext.h
pcomplete.o: bashintl.h ${LIBINTL_H} $(BASHINCDIR)/gettext.h
pcomplib.o: bashintl.h ${LIBINTL_H} $(BASHINCDIR)/gettext.h
print_cmd.o: bashintl.h ${LIBINTL_H} $(BASHINCDIR)/gettext.h

96
NEWS
View File

@ -1,3 +1,99 @@
This is a terse description of the new features added to bash-4.2 since
the release of bash-4.1. As always, the manual page (doc/bash.1) is
the place to look for complete descriptions.
1. New Features in Bash
a. `exec -a foo' now sets $0 to `foo' in an executable shell script without a
leading #!.
b. Subshells begun to execute command substitutions or run shell functions or
builtins in subshells do not reset trap strings until a new trap is
specified. This allows $(trap) to display the caller's traps and the
trap strings to persist until a new trap is set.
c. `trap -p' will now show signals ignored at shell startup, though their
disposition still cannot be modified.
d. $'...', echo, and printf understand \uXXXX and \UXXXXXXXX escape sequences.
e. declare/typeset has a new `-g' option, which creates variables in the
global scope even when run in a shell function.
f. test/[/[[ have a new -v variable unary operator, which returns success if
`variable' has been set.
g. Posix parsing changes to allow `! time command' and multiple consecutive
instances of `!' (which toggle) and `time' (which have no cumulative
effect).
h. Posix change to allow `time' as a command by itself to print the elapsed
user, system, and real times for the shell and its children.
j. $((...)) is always parsed as an arithmetic expansion first, instead of as
a potential nested command substitution, as Posix requires.
k. A new FUNCNEST variable to allow the user to control the maximum shell
function nesting (recursive execution) level.
l. The mapfile builtin now supplies a third argument to the callback command:
the line about to be assigned to the supplied array index.
m. The printf builtin has a new %(fmt)T specifier, which allows time values
to use strftime-like formatting.
n. There is a new `compat41' shell option.
o. The cd builtin has a new Posix-mandated `-e' option.
p. Negative subscripts to indexed arrays, previously errors, now are treated
as offsets from the maximum assigned index + 1.
q. Negative length specifications in the ${var:offset:length} expansion,
previously errors, are now treated as offsets from the end of the variable.
r. Parsing change to allow `time -p --'.
s. Posix-mode parsing change to not recognize `time' as a keyword if the
following token begins with a `-'. This means no more Posix-mode
`time -p'. Posix interpretation 267.
t. There is a new `lastpipe' shell option that runs the last command of a
pipeline in the current shell context. The lastpipe option has no
effect if job control is enabled.
u. History expansion no longer expands the `$!' variable expansion.
v. Posix mode shells no longer exit if a variable assignment error occurs
with an assignment preceding a command that is not a special builtin.
w. Non-interactive mode shells exit if -u is enabled and an attempt is made
to use an unset variable with the % or # expansions, the `//', `^', or
`,' expansions, or the parameter length expansion.
x. Posix-mode shells use the argument passed to `.' as-is if a $PATH search
fails, effectively searching the current directory. Posix-2008 change.
2. New Features in Readline
a. The history library does not try to write the history filename in the
current directory if $HOME is unset. This closes a potential security
problem if the application does not specify a history filename.
b. New bindable variable `completion-display-width' to set the number of
columns used when displaying completions.
c. New bindable variable `completion-case-map' to cause case-insensitive
completion to treat `-' and `_' as identical.
d. There are new bindable vi-mode command names to avoid readline's case-
insensitive matching not allowing them to be bound separately.
e. New bindable variable `menu-complete-display-prefix' causes the menu
completion code to display the common prefix of the possible completions
before cycling through the list, instead of after.
-------------------------------------------------------------------------------
This is a terse description of the new features added to bash-4.1 since
the release of bash-4.0. As always, the manual page (doc/bash.1) is
the place to look for complete descriptions.

87
POSIX
View File

@ -55,116 +55,129 @@ The following list is what's changed when `POSIX mode' is in effect:
13. Non-interactive shells exit if a syntax error in an arithmetic
expansion results in an invalid expression.
14. Redirection operators do not perform filename expansion on the word
14. Non-interactive shells exit if there is a syntax error in a script
read with the `.' or `source' builtins, or in a string processed by
the `eval' builtin.
15. Redirection operators do not perform filename expansion on the word
in the redirection unless the shell is interactive.
15. Redirection operators do not perform word splitting on the word in
16. Redirection operators do not perform word splitting on the word in
the redirection.
16. Function names must be valid shell `name's. That is, they may not
17. Function names must be valid shell `name's. That is, they may not
contain characters other than letters, digits, and underscores, and
may not start with a digit. Declaring a function with an invalid
name causes a fatal syntax error in non-interactive shells.
17. POSIX special builtins are found before shell functions during
18. POSIX special builtins are found before shell functions during
command lookup.
18. If a POSIX special builtin returns an error status, a
19. The `time' reserved word may be used by itself as a command. When
used in this way, it displays timing statistics for the shell and
its completed children. The `TIMEFORMAT' variable controls the
format of the timing information.
20. When parsing and expanding a ${...} expansion that appears within
double quotes, single quotes are no longer special and cannot be
used to quote a closing brace or other special character, unless
the operator is one of those defined to perform pattern removal.
In this case, they do not have to appear as matched pairs.
21. The parser does not recognize `time' as a reserved word if the next
token begins with a `-'.
22. If a POSIX special builtin returns an error status, a
non-interactive shell exits. The fatal errors are those listed in
the POSIX standard, and include things like passing incorrect
options, redirection errors, variable assignment errors for
assignments preceding the command name, and so on.
19. If `CDPATH' is set, the `cd' builtin will not implicitly append
the current directory to it. This means that `cd' will fail if no
valid directory name can be constructed from any of the entries in
`$CDPATH', even if the a directory with the same name as the name
given as an argument to `cd' exists in the current directory.
20. A non-interactive shell exits with an error status if a variable
23. A non-interactive shell exits with an error status if a variable
assignment error occurs when no command name follows the assignment
statements. A variable assignment error occurs, for example, when
trying to assign a value to a readonly variable.
21. A non-interactive shell exits with an error status if the iteration
24. A non-interactive shell exists with an error status if a variable
assignment error occurs in an assignment statement preceding a
special builtin, but not with any other simple command.
25. A non-interactive shell exits with an error status if the iteration
variable in a `for' statement or the selection variable in a
`select' statement is a readonly variable.
22. Process substitution is not available.
26. Process substitution is not available.
23. Assignment statements preceding POSIX special builtins persist in
27. Assignment statements preceding POSIX special builtins persist in
the shell environment after the builtin completes.
24. Assignment statements preceding shell function calls persist in the
28. Assignment statements preceding shell function calls persist in the
shell environment after the function returns, as if a POSIX
special builtin command had been executed.
25. The `export' and `readonly' builtin commands display their output
29. The `export' and `readonly' builtin commands display their output
in the format required by POSIX.
26. The `trap' builtin displays signal names without the leading `SIG'.
30. The `trap' builtin displays signal names without the leading `SIG'.
27. The `trap' builtin doesn't check the first argument for a possible
31. The `trap' builtin doesn't check the first argument for a possible
signal specification and revert the signal handling to the original
disposition if it is, unless that argument consists solely of
digits and is a valid signal number. If users want to reset the
handler for a given signal to the original disposition, they
should use `-' as the first argument.
28. The `.' and `source' builtins do not search the current directory
32. The `.' and `source' builtins do not search the current directory
for the filename argument if it is not found by searching `PATH'.
29. Subshells spawned to execute command substitutions inherit the
33. Subshells spawned to execute command substitutions inherit the
value of the `-e' option from the parent shell. When not in POSIX
mode, Bash clears the `-e' option in such subshells.
30. Alias expansion is always enabled, even in non-interactive shells.
34. Alias expansion is always enabled, even in non-interactive shells.
31. When the `alias' builtin displays alias definitions, it does not
35. When the `alias' builtin displays alias definitions, it does not
display them with a leading `alias ' unless the `-p' option is
supplied.
32. When the `set' builtin is invoked without options, it does not
36. When the `set' builtin is invoked without options, it does not
display shell function names and definitions.
33. When the `set' builtin is invoked without options, it displays
37. When the `set' builtin is invoked without options, it displays
variable values without quotes, unless they contain shell
metacharacters, even if the result contains nonprinting characters.
34. When the `cd' builtin is invoked in LOGICAL mode, and the pathname
38. When the `cd' builtin is invoked in LOGICAL mode, and the pathname
constructed from `$PWD' and the directory name supplied as an
argument does not refer to an existing directory, `cd' will fail
instead of falling back to PHYSICAL mode.
35. When the `pwd' builtin is supplied the `-P' option, it resets
`$PWD' to a pathname containing no symlinks.
36. The `pwd' builtin verifies that the value it prints is the same as
39. The `pwd' builtin verifies that the value it prints is the same as
the current directory, even if it is not asked to check the file
system with the `-P' option.
37. When listing the history, the `fc' builtin does not include an
40. When listing the history, the `fc' builtin does not include an
indication of whether or not a history entry has been modified.
38. The default editor used by `fc' is `ed'.
41. The default editor used by `fc' is `ed'.
39. The `type' and `command' builtins will not report a non-executable
42. The `type' and `command' builtins will not report a non-executable
file as having been found, though the shell will attempt to
execute such a file if it is the only so-named file found in
`$PATH'.
40. The `vi' editing mode will invoke the `vi' editor directly when
43. The `vi' editing mode will invoke the `vi' editor directly when
the `v' command is run, instead of checking `$VISUAL' and
`$EDITOR'.
41. When the `xpg_echo' option is enabled, Bash does not attempt to
44. When the `xpg_echo' option is enabled, Bash does not attempt to
interpret any arguments to `echo' as options. Each argument is
displayed, after escape characters are converted.
42. The `ulimit' builtin uses a block size of 512 bytes for the `-c'
45. The `ulimit' builtin uses a block size of 512 bytes for the `-c'
and `-f' options.
43. The arrival of `SIGCHLD' when a trap is set on `SIGCHLD' does not
46. The arrival of `SIGCHLD' when a trap is set on `SIGCHLD' does not
interrupt the `wait' builtin and cause it to return immediately.
The trap command is run once for each child that exits.

18
README
View File

@ -1,8 +1,8 @@
Introduction
============
This is GNU Bash, version 4.1. Bash is the GNU Project's Bourne
Again SHell, a complete implementation of the POSIX.2 shell spec,
This is GNU Bash, version 4.2. Bash is the GNU Project's Bourne
Again SHell, a complete implementation of the POSIX shell spec,
but also with interactive command line editing, job control on
architectures that support it, csh-like features such as history
substitution and brace expansion, and a slew of other features.
@ -12,11 +12,11 @@ large Unix-style man page. The man page is the definitive description
of the shell's features.
See the file POSIX for a discussion of how the Bash defaults differ
from the POSIX.2 spec and a description of the Bash `posix mode'.
from the POSIX spec and a description of the Bash `posix mode'.
There are some user-visible incompatibilities between this version
of Bash and previous widely-distributed versions, bash-3.2 and
bash-4.0. For details, see the file COMPAT. The NEWS file tersely
of Bash and previous widely-distributed versions, bash-4.0 and
bash-4.1. For details, see the file COMPAT. The NEWS file tersely
lists features that are new in this release.
Bash is free software, distributed under the terms of the [GNU] General
@ -27,10 +27,10 @@ see the file COPYING.
A number of frequently-asked questions are answered in the file
`doc/FAQ'.
To compile Bash, try typing `./configure', then `make'. Bash
auto-configures the build process, so no further intervention
should be necessary. Bash builds with `gcc' by default if it is
available. If you want to use `cc' instead, type
To compile Bash, type `./configure', then `make'. Bash auto-configures
the build process, so no further intervention should be necessary. Bash
builds with `gcc' by default if it is available. If you want to use `cc'
instead, type
CC=cc ./configure

52
aclocal.m4 vendored
View File

@ -1695,8 +1695,10 @@ AC_CHECK_HEADERS(langinfo.h)
AC_CHECK_FUNC(mbrlen, AC_DEFINE(HAVE_MBRLEN))
AC_CHECK_FUNC(mbscasecmp, AC_DEFINE(HAVE_MBSCMP))
AC_CHECK_FUNC(mbscmp, AC_DEFINE(HAVE_MBSCMP))
AC_CHECK_FUNC(mbsnrtowcs, AC_DEFINE(HAVE_MBSNRTOWCS))
AC_CHECK_FUNC(mbsrtowcs, AC_DEFINE(HAVE_MBSRTOWCS))
AC_REPLACE_FUNCS(mbschr)
AC_CHECK_FUNC(wcrtomb, AC_DEFINE(HAVE_WCRTOMB))
@ -1705,6 +1707,8 @@ AC_CHECK_FUNC(wcsdup, AC_DEFINE(HAVE_WCSDUP))
AC_CHECK_FUNC(wcwidth, AC_DEFINE(HAVE_WCWIDTH))
AC_CHECK_FUNC(wctype, AC_DEFINE(HAVE_WCTYPE))
AC_REPLACE_FUNCS(wcswidth)
dnl checks for both mbrtowc and mbstate_t
AC_FUNC_MBRTOWC
if test $ac_cv_func_mbrtowc = yes; then
@ -4115,3 +4119,51 @@ main()
[Define if you have a standard-conformant vsnprintf function.])
fi
])
AC_DEFUN(BASH_STRUCT_WEXITSTATUS_OFFSET,
[AC_MSG_CHECKING(for offset of exit status in return status from wait)
AC_CACHE_VAL(bash_cv_wexitstatus_offset,
[AC_RUN_IFELSE([
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
main(c, v)
int c;
char **v;
{
pid_t pid, p;
int s, i, n;
s = 0;
pid = fork();
if (pid == 0)
exit (42);
/* wait for the process */
p = wait(&s);
if (p != pid)
exit (255);
/* crack s */
for (i = 0; i < (sizeof(s) - 8); i++)
{
n = (s >> i) & 0xff;
if (n == 42)
exit (i);
}
exit (254);
}
], bash_cv_wexitstatus_offset=0, bash_cv_wexitstatus_offset=$?,
[AC_MSG_WARN(cannot check WEXITSTATUS offset if cross compiling -- defaulting to 0)
bash_cv_wexitstatus_offset=0]
)])
if test "$bash_cv_wexitstatus_offset" -gt 32 ; then
AC_MSG_WARN(bad exit status from test program -- defaulting to 0)
bash_cv_wexitstatus_offset=0
fi
AC_MSG_RESULT($bash_cv_wexitstatus_offset)
AC_DEFINE_UNQUOTED([WEXITSTATUS_OFFSET], [$bash_cv_wexitstatus_offset], [Offset of exit status in wait status word])
])

View File

@ -319,6 +319,8 @@ skipquotes (string, start)
if (string[i] == '\\')
{
i++; /* skip backslash-quoted quote characters, too */
if (string[i] == 0)
break;
continue;
}
@ -364,6 +366,8 @@ skipws (string, start)
if (string[i] == '\\')
{
peekc = string[i+1];
if (peekc == 0)
break;
if (ISLETTER (peekc))
backslash_quoted_word++; /* this is a backslash-quoted word */
else
@ -429,6 +433,8 @@ rd_token (string, start)
if (string[i] == '\\')
{
i++; /* skip backslash-escaped character */
if (string[i] == 0)
break;
continue;
}

View File

@ -1,6 +1,6 @@
/* arrayfunc.c -- High-level array functions used by other parts of the shell. */
/* Copyright (C) 2001-2009 Free Software Foundation, Inc.
/* Copyright (C) 2001-2010 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@ -44,7 +44,7 @@ static SHELL_VAR *bind_array_var_internal __P((SHELL_VAR *, arrayind_t, char *,
static char *quote_assign __P((const char *));
static void quote_array_assignment_chars __P((WORD_LIST *));
static char *array_value_internal __P((char *, int, int, int *));
static char *array_value_internal __P((char *, int, int, int *, arrayind_t *));
/* Standard error message to use when encountering an invalid array subscript */
const char * const bash_badsub_errmsg = N_("bad array subscript");
@ -658,6 +658,7 @@ unbind_array_element (var, sub)
return -1;
}
assoc_remove (assoc_cell (var), akey);
free (akey);
}
else
{
@ -842,15 +843,31 @@ array_variable_part (s, subp, lenp)
return (var == 0 || invisible_p (var)) ? (SHELL_VAR *)0 : var;
}
#define INDEX_ERROR() \
do \
{ \
if (var) \
err_badarraysub (var->name); \
else \
{ \
t[-1] = '\0'; \
err_badarraysub (s); \
t[-1] = '['; /* ] */\
} \
return ((char *)NULL); \
} \
while (0)
/* Return a string containing the elements in the array and subscript
described by S. If the subscript is * or @, obeys quoting rules akin
to the expansion of $* and $@ including double quoting. If RTYPE
is non-null it gets 1 if the array reference is name[*], 2 if the
reference is name[@], and 0 otherwise. */
static char *
array_value_internal (s, quoted, allow_all, rtype)
array_value_internal (s, quoted, flags, rtype, indp)
char *s;
int quoted, allow_all, *rtype;
int quoted, flags, *rtype;
arrayind_t *indp;
{
int len;
arrayind_t ind;
@ -876,12 +893,12 @@ array_value_internal (s, quoted, allow_all, rtype)
{
if (rtype)
*rtype = (t[0] == '*') ? 1 : 2;
if (allow_all == 0)
if ((flags & AV_ALLOWALL) == 0)
{
err_badarraysub (s);
return ((char *)NULL);
}
else if (var == 0 || value_cell (var) == 0)
else if (var == 0 || value_cell (var) == 0) /* XXX - check for invisible_p(var) ? */
return ((char *)NULL);
else if (array_p (var) == 0 && assoc_p (var) == 0)
l = add_string_to_list (value_cell (var), (WORD_LIST *)NULL);
@ -915,20 +932,22 @@ array_value_internal (s, quoted, allow_all, rtype)
*rtype = 0;
if (var == 0 || array_p (var) || assoc_p (var) == 0)
{
ind = array_expand_index (t, len);
if (ind < 0)
if ((flags & AV_USEIND) == 0 || indp == 0)
{
index_error:
if (var)
err_badarraysub (var->name);
else
ind = array_expand_index (t, len);
if (ind < 0)
{
t[-1] = '\0';
err_badarraysub (s);
t[-1] = '['; /* ] */
/* negative subscripts to indexed arrays count back from end */
if (var && array_p (var))
ind = array_max_index (array_cell (var)) + 1 + ind;
if (ind < 0)
INDEX_ERROR();
}
return ((char *)NULL);
if (indp)
*indp = ind;
}
else if (indp)
ind = *indp;
}
else if (assoc_p (var))
{
@ -936,15 +955,18 @@ index_error:
akey = expand_assignment_string_to_string (t, 0); /* [ */
t[len - 1] = ']';
if (akey == 0 || *akey == 0)
goto index_error;
INDEX_ERROR();
}
if (var == 0)
if (var == 0 || value_cell (var) == 0) /* XXX - check invisible_p(var) ? */
return ((char *)NULL);
if (array_p (var) == 0 && assoc_p (var) == 0)
return (ind == 0 ? value_cell (var) : (char *)NULL);
else if (assoc_p (var))
retval = assoc_reference (assoc_cell (var), akey);
{
retval = assoc_reference (assoc_cell (var), akey);
free (akey);
}
else
retval = array_reference (array_cell (var), ind);
}
@ -955,23 +977,25 @@ index_error:
/* Return a string containing the elements described by the array and
subscript contained in S, obeying quoting for subscripts * and @. */
char *
array_value (s, quoted, rtype)
array_value (s, quoted, flags, rtype, indp)
char *s;
int quoted, *rtype;
int quoted, flags, *rtype;
arrayind_t *indp;
{
return (array_value_internal (s, quoted, 1, rtype));
return (array_value_internal (s, quoted, flags|AV_ALLOWALL, rtype, indp));
}
/* Return the value of the array indexing expression S as a single string.
If ALLOW_ALL is 0, do not allow `@' and `*' subscripts. This is used
by other parts of the shell such as the arithmetic expression evaluator
in expr.c. */
If (FLAGS & AV_ALLOWALL) is 0, do not allow `@' and `*' subscripts. This
is used by other parts of the shell such as the arithmetic expression
evaluator in expr.c. */
char *
get_array_value (s, allow_all, rtype)
get_array_value (s, flags, rtype, indp)
char *s;
int allow_all, *rtype;
int flags, *rtype;
arrayind_t *indp;
{
return (array_value_internal (s, 0, allow_all, rtype));
return (array_value_internal (s, 0, flags, rtype, indp));
}
char *
@ -990,6 +1014,9 @@ array_keys (s, quoted)
if (var == 0 || ALL_ELEMENT_SUB (t[0]) == 0 || t[1] != ']')
return (char *)NULL;
if (var_isset (var) == 0 || invisible_p (var))
return (char *)NULL;
if (array_p (var) == 0 && assoc_p (var) == 0)
l = add_string_to_list ("0", (WORD_LIST *)NULL);
else if (assoc_p (var))

View File

@ -1,6 +1,6 @@
/* arrayfunc.h -- declarations for miscellaneous array functions in arrayfunc.c */
/* Copyright (C) 2001-2009 Free Software Foundation, Inc.
/* Copyright (C) 2001-2010 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@ -25,6 +25,11 @@
#if defined (ARRAY_VARS)
/* Flags for array_value_internal and callers array_value/get_array_value */
#define AV_ALLOWALL 0x001
#define AV_QUOTED 0x002
#define AV_USEIND 0x004
extern SHELL_VAR *convert_var_to_array __P((SHELL_VAR *));
extern SHELL_VAR *convert_var_to_assoc __P((SHELL_VAR *));
@ -51,8 +56,8 @@ extern void print_assoc_assignment __P((SHELL_VAR *, int));
extern arrayind_t array_expand_index __P((char *, int));
extern int valid_array_reference __P((char *));
extern char *array_value __P((char *, int, int *));
extern char *get_array_value __P((char *, int, int *));
extern char *array_value __P((char *, int, int, int *, arrayind_t *));
extern char *get_array_value __P((char *, int, int *, arrayind_t *));
extern char *array_keys __P((char *, int));

31473
autom4te.cache/output.0 Normal file

File diff suppressed because it is too large Load Diff

67
autom4te.cache/requests Normal file
View File

@ -0,0 +1,67 @@
# This file was generated.
# It contains the lists of macros which have been traced.
# It can be safely removed.
@request = (
bless( [
'0',
1,
[
'/sw/share/autoconf'
],
[
'/sw/share/autoconf/autoconf/autoconf.m4f',
'aclocal.m4',
'configure.in'
],
{
'_LT_AC_TAGCONFIG' => 1,
'AM_PROG_F77_C_O' => 1,
'AC_INIT' => 1,
'm4_pattern_forbid' => 1,
'_AM_COND_IF' => 1,
'AC_CANONICAL_TARGET' => 1,
'AC_SUBST' => 1,
'AC_CONFIG_LIBOBJ_DIR' => 1,
'AC_FC_SRCEXT' => 1,
'AC_CANONICAL_HOST' => 1,
'AC_PROG_LIBTOOL' => 1,
'AM_INIT_AUTOMAKE' => 1,
'AC_CONFIG_SUBDIRS' => 1,
'AM_AUTOMAKE_VERSION' => 1,
'LT_CONFIG_LTDL_DIR' => 1,
'AC_REQUIRE_AUX_FILE' => 1,
'AC_CONFIG_LINKS' => 1,
'm4_sinclude' => 1,
'LT_SUPPORTED_TAG' => 1,
'AM_MAINTAINER_MODE' => 1,
'AM_GNU_GETTEXT_INTL_SUBDIR' => 1,
'_m4_warn' => 1,
'AM_PROG_CXX_C_O' => 1,
'_AM_COND_ENDIF' => 1,
'AM_ENABLE_MULTILIB' => 1,
'AC_CONFIG_FILES' => 1,
'include' => 1,
'LT_INIT' => 1,
'AM_GNU_GETTEXT' => 1,
'AC_LIBSOURCE' => 1,
'AM_PROG_FC_C_O' => 1,
'AC_CANONICAL_BUILD' => 1,
'AC_FC_FREEFORM' => 1,
'AH_OUTPUT' => 1,
'_AM_SUBST_NOTMAKE' => 1,
'AC_CONFIG_AUX_DIR' => 1,
'sinclude' => 1,
'm4_pattern_allow' => 1,
'AM_PROG_CC_C_O' => 1,
'AC_CANONICAL_SYSTEM' => 1,
'AM_CONDITIONAL' => 1,
'AC_CONFIG_HEADERS' => 1,
'AC_DEFINE_TRACE_LITERAL' => 1,
'm4_include' => 1,
'_AM_COND_ELSE' => 1,
'AC_SUBST_TRACE' => 1
}
], 'Autom4te::Request' )
);

2515
autom4te.cache/traces.0 Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
/* bashhist.c -- bash interface to the GNU history library. */
/* Copyright (C) 1993-2009 Free Software Foundation, Inc.
/* Copyright (C) 1993-2010 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@ -184,6 +184,7 @@ int dont_save_function_defs;
extern int current_command_line_count;
extern struct dstack dstack;
extern int parser_state;
static int bash_history_inhibit_expansion __P((char *, int));
#if defined (READLINE)
@ -212,6 +213,9 @@ bash_history_inhibit_expansion (string, i)
else if (i > 1 && string[i - 1] == '{' && string[i - 2] == '$' &&
member ('}', string + i + 1))
return (1);
/* The shell uses $! as a defined parameter expansion. */
else if (i > 1 && string[i - 1] == '$' && string[i] == '!')
return (1);
#if defined (EXTENDED_GLOB)
else if (extended_glob && i > 1 && string[i+1] == '(' && member (')', string + i + 2))
return (1);
@ -355,7 +359,7 @@ save_history ()
the history file. */
using_history ();
if (history_lines_this_session < where_history () || force_append_history)
if (history_lines_this_session <= where_history () || force_append_history)
append_history (history_lines_this_session, hf);
else
write_history (hf);
@ -372,7 +376,7 @@ maybe_append_history (filename)
struct stat buf;
result = EXECUTION_SUCCESS;
if (history_lines_this_session && (history_lines_this_session < where_history ()))
if (history_lines_this_session && (history_lines_this_session <= where_history ()))
{
/* If the filename was supplied, then create it if necessary. */
if (stat (filename, &buf) == -1 && errno == ENOENT)
@ -731,7 +735,7 @@ bash_add_history (line)
add_it = 1;
if (command_oriented_history && current_command_line_count > 1)
{
chars_to_add = literal_history ? "\n" : history_delimiting_chars ();
chars_to_add = literal_history ? "\n" : history_delimiting_chars (line);
using_history ();
current = previous_history ();
@ -751,6 +755,13 @@ bash_add_history (line)
chars_to_add = "";
}
/* If we're not in some kind of quoted construct, the current history
entry ends with a newline, and we're going to add a semicolon,
don't. In some cases, it results in a syntax error (e.g., before
a close brace), and it should not be needed. */
if (dstack.delimiter_depth == 0 && current->line[curlen - 1] == '\n' && *chars_to_add == ';')
chars_to_add++;
new_line = (char *)xmalloc (1
+ curlen
+ strlen (line)

View File

@ -1,6 +1,6 @@
/* bashline.c -- Bash's interface to the readline library. */
/* Copyright (C) 1987-2009 Free Software Foundation, Inc.
/* Copyright (C) 1987-2011 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@ -175,7 +175,8 @@ static char **prog_complete_matches;
extern int hist_verify;
#endif
extern int current_command_line_count, last_command_exit_value;
extern int current_command_line_count, saved_command_line_count;
extern int last_command_exit_value;
extern int array_needs_making;
extern int posixly_correct, no_symbolic_links;
extern char *current_prompt_string, *ps1_prompt;
@ -500,7 +501,7 @@ initialize_readline ()
/* Tell the completer that we might want to follow symbolic links or
do other expansion on directory names. */
rl_directory_completion_hook = bash_directory_completion_hook;
rl_directory_rewrite_hook = bash_directory_completion_hook;
rl_filename_rewrite_hook = bash_filename_rewrite_hook;
@ -528,11 +529,8 @@ initialize_readline ()
enable_hostname_completion (perform_hostname_completion);
/* characters that need to be quoted when appearing in filenames. */
#if 0
rl_filename_quote_characters = " \t\n\\\"'@<>=;|&()#$`?*[!:{"; /*}*/
#else
rl_filename_quote_characters = " \t\n\\\"'@<>=;|&()#$`?*[!:{~"; /*}*/
#endif
rl_filename_quoting_function = bash_quote_filename;
rl_filename_dequoting_function = bash_dequote_filename;
rl_char_is_quoted_p = char_is_quoted;
@ -566,7 +564,7 @@ bashline_reset ()
tilde_initialize ();
rl_attempted_completion_function = attempt_shell_completion;
rl_completion_entry_function = NULL;
rl_directory_completion_hook = bash_directory_completion_hook;
rl_directory_rewrite_hook = bash_directory_completion_hook;
rl_ignore_some_completions_function = filename_completion_ignore;
}
@ -862,10 +860,11 @@ edit_and_execute_command (count, c, editing_mode, edit_command)
char *edit_command;
{
char *command, *metaval;
int r, cclc, rrs, metaflag;
int r, rrs, metaflag;
sh_parser_state_t ps;
rrs = rl_readline_state;
cclc = current_command_line_count;
saved_command_line_count = current_command_line_count;
/* Accept the current line. */
rl_newline (1, c);
@ -881,6 +880,8 @@ edit_and_execute_command (count, c, editing_mode, edit_command)
then call fc to operate on it. We have to add a dummy command to
the end of the history because fc ignores the last command (assumes
it's supposed to deal with the command before the `fc'). */
/* This breaks down when using command-oriented history and are not
finished with the command, so we should not ignore the last command */
using_history ();
bash_add_history (rl_line_buffer);
bash_add_history ("");
@ -897,11 +898,13 @@ edit_and_execute_command (count, c, editing_mode, edit_command)
yet. */
if (rl_deprep_term_function)
(*rl_deprep_term_function) ();
save_parser_state (&ps);
r = parse_and_execute (command, (editing_mode == VI_EDITING_MODE) ? "v" : "C-xC-e", SEVAL_NOHIST);
restore_parser_state (&ps);
if (rl_prep_term_function)
(*rl_prep_term_function) (metaflag);
current_command_line_count = cclc;
current_command_line_count = saved_command_line_count;
/* Now erase the contents of the current line and undo the effects of the
rl_accept_line() above. We don't even want to make the text we just
@ -990,6 +993,20 @@ bash_forward_shellword (count, key)
return 0;
}
/* Are we in a quoted string? If we are, move to the end of the quoted
string and continue the outer loop. We only want quoted strings, not
backslash-escaped characters, but char_is_quoted doesn't
differentiate. */
if (char_is_quoted (rl_line_buffer, p) && p > 0 && rl_line_buffer[p-1] != '\\')
{
do
ADVANCE_CHAR (rl_line_buffer, slen, p);
while (p < rl_end && char_is_quoted (rl_line_buffer, p));
count--;
continue;
}
/* Rest of code assumes we are not in a quoted string. */
/* Move forward until we hit a non-metacharacter. */
while (p < rl_end && (c = rl_line_buffer[p]) && WORDDELIM (c))
{
@ -1397,12 +1414,12 @@ bash_default_completion (text, start, end, qc, compflags)
/* If the word starts in `~', and there is no slash in the word, then
try completing this word as a username. */
if (matches ==0 && *text == '~' && mbschr (text, '/') == 0)
if (matches == 0 && *text == '~' && mbschr (text, '/') == 0)
matches = rl_completion_matches (text, rl_username_completion_function);
/* Another one. Why not? If the word starts in '@', then look through
the world of known hostnames for completion first. */
if (!matches && perform_hostname_completion && *text == '@')
if (matches == 0 && perform_hostname_completion && *text == '@')
matches = rl_completion_matches (text, hostname_completion_function);
/* And last, (but not least) if this word is in a command position, then
@ -2648,8 +2665,7 @@ bash_directory_expansion (dirname)
if (rl_directory_rewrite_hook)
(*rl_directory_rewrite_hook) (&d);
if (rl_directory_completion_hook && (*rl_directory_completion_hook) (&d))
else if (rl_directory_completion_hook && (*rl_directory_completion_hook) (&d))
{
free (*dirname);
*dirname = d;
@ -2678,7 +2694,9 @@ bash_filename_rewrite_hook (fname, fnlen)
}
/* Handle symbolic link references and other directory name
expansions while hacking completion. */
expansions while hacking completion. This should return 1 if it modifies
the DIRNAME argument, 0 otherwise. It should make sure not to modify
DIRNAME if it returns 0. */
static int
bash_directory_completion_hook (dirname)
char **dirname;
@ -2735,6 +2753,7 @@ bash_directory_completion_hook (dirname)
{
/* Dequote the filename even if we don't expand it. */
new_dirname = bash_dequote_filename (local_dirname, rl_completion_quote_character);
return_value = STREQ (local_dirname, new_dirname) == 0;
free (local_dirname);
local_dirname = *dirname = new_dirname;
}
@ -2758,14 +2777,14 @@ bash_directory_completion_hook (dirname)
free (temp1);
temp1 = temp2;
temp2 = sh_canonpath (temp1, PATH_CHECKDOTDOT|PATH_CHECKEXISTS);
return_value = temp2 != 0;
return_value |= temp2 != 0;
}
}
/* If we can't canonicalize, bail. */
if (temp2 == 0)
{
free (temp1);
return 1;
return return_value;
}
len1 = strlen (temp1);
if (temp1[len1 - 1] == '/')
@ -2778,10 +2797,12 @@ bash_directory_completion_hook (dirname)
temp2[len2 + 1] = '\0';
}
}
return_value |= STREQ (local_dirname, temp2) == 0;
free (local_dirname);
*dirname = temp2;
free (temp1);
}
return (return_value);
}
@ -2870,12 +2891,15 @@ dynamic_complete_history (count, key)
int r;
rl_compentry_func_t *orig_func;
rl_completion_func_t *orig_attempt_func;
rl_compignore_func_t *orig_ignore_func;
orig_func = rl_completion_entry_function;
orig_attempt_func = rl_attempted_completion_function;
orig_ignore_func = rl_ignore_some_completions_function;
rl_completion_entry_function = history_completion_generator;
rl_attempted_completion_function = (rl_completion_func_t *)NULL;
rl_ignore_some_completions_function = filename_completion_ignore;
/* XXX - use rl_completion_mode here? */
if (rl_last_func == dynamic_complete_history)
@ -2885,6 +2909,8 @@ dynamic_complete_history (count, key)
rl_completion_entry_function = orig_func;
rl_attempted_completion_function = orig_attempt_func;
rl_ignore_some_completions_function = orig_ignore_func;
return r;
}
@ -2895,14 +2921,17 @@ bash_dabbrev_expand (count, key)
int r, orig_suppress, orig_sort;
rl_compentry_func_t *orig_func;
rl_completion_func_t *orig_attempt_func;
rl_compignore_func_t *orig_ignore_func;
orig_func = rl_menu_completion_entry_function;
orig_attempt_func = rl_attempted_completion_function;
orig_ignore_func = rl_ignore_some_completions_function;
orig_suppress = rl_completion_suppress_append;
orig_sort = rl_sort_completion_matches;
rl_menu_completion_entry_function = history_completion_generator;
rl_attempted_completion_function = (rl_completion_func_t *)NULL;
rl_ignore_some_completions_function = filename_completion_ignore;
rl_filename_completion_desired = 0;
rl_completion_suppress_append = 1;
rl_sort_completion_matches = 0;
@ -2917,6 +2946,7 @@ bash_dabbrev_expand (count, key)
rl_last_func = bash_dabbrev_expand;
rl_menu_completion_entry_function = orig_func;
rl_attempted_completion_function = orig_attempt_func;
rl_ignore_some_completions_function = orig_ignore_func;
rl_completion_suppress_append = orig_suppress;
rl_sort_completion_matches = orig_sort;
@ -2966,23 +2996,27 @@ bash_complete_filename_internal (what_to_do)
rl_compentry_func_t *orig_func;
rl_completion_func_t *orig_attempt_func;
rl_icppfunc_t *orig_dir_func;
rl_compignore_func_t *orig_ignore_func;
/*const*/ char *orig_rl_completer_word_break_characters;
int r;
orig_func = rl_completion_entry_function;
orig_attempt_func = rl_attempted_completion_function;
orig_dir_func = rl_directory_completion_hook;
orig_dir_func = rl_directory_rewrite_hook;
orig_ignore_func = rl_ignore_some_completions_function;
orig_rl_completer_word_break_characters = rl_completer_word_break_characters;
rl_completion_entry_function = rl_filename_completion_function;
rl_attempted_completion_function = (rl_completion_func_t *)NULL;
rl_directory_completion_hook = (rl_icppfunc_t *)NULL;
rl_directory_rewrite_hook = (rl_icppfunc_t *)NULL;
rl_ignore_some_completions_function = filename_completion_ignore;
rl_completer_word_break_characters = " \t\n\"\'";
r = rl_complete_internal (what_to_do);
rl_completion_entry_function = orig_func;
rl_attempted_completion_function = orig_attempt_func;
rl_directory_completion_hook = orig_dir_func;
rl_directory_rewrite_hook = orig_dir_func;
rl_ignore_some_completions_function = orig_ignore_func;
rl_completer_word_break_characters = orig_rl_completer_word_break_characters;
return r;
@ -3160,17 +3194,21 @@ bash_specific_completion (what_to_do, generator)
{
rl_compentry_func_t *orig_func;
rl_completion_func_t *orig_attempt_func;
rl_compignore_func_t *orig_ignore_func;
int r;
orig_func = rl_completion_entry_function;
orig_attempt_func = rl_attempted_completion_function;
orig_ignore_func = rl_ignore_some_completions_function;
rl_completion_entry_function = generator;
rl_attempted_completion_function = NULL;
rl_ignore_some_completions_function = orig_ignore_func;
r = rl_complete_internal (what_to_do);
rl_completion_entry_function = orig_func;
rl_attempted_completion_function = orig_attempt_func;
rl_ignore_some_completions_function = orig_ignore_func;
return r;
}
@ -3421,7 +3459,10 @@ static int
putx(c)
int c;
{
putc (c, rl_outstream);
int x;
x = putc (c, rl_outstream);
return (x);
}
static int

View File

@ -63,7 +63,7 @@ static const int brace_arg_separator = ',';
static int brace_gobbler __P((char *, size_t, int *, int));
static char **expand_amble __P((char *, size_t, int));
static char **expand_seqterm __P((char *, size_t));
static char **mkseq __P((int, int, int, int, int));
static char **mkseq __P((intmax_t, intmax_t, int, int, int));
static char **array_concat __P((char **, char **));
#else
static int brace_gobbler ();
@ -307,13 +307,15 @@ expand_amble (text, tlen, flags)
static char **
mkseq (start, end, incr, type, width)
int start, end, incr, type, width;
intmax_t start, end;
int incr, type, width;
{
int n, i;
intmax_t n;
int i;
char **result, *t;
n = abs (end - start) + 1;
result = strvec_create (n + 1);
i = abs (end - start) + 1;
result = strvec_create (i + 1);
if (incr == 0)
incr = 1;
@ -335,8 +337,9 @@ mkseq (start, end, incr, type, width)
result[i++] = itos (n);
else if (type == ST_ZINT)
{
int len;
len = asprintf (&t, "%0*d", width, n);
int len, arg;
arg = n;
len = asprintf (&t, "%0*d", width, arg);
result[i++] = t;
}
else
@ -362,7 +365,8 @@ expand_seqterm (text, tlen)
size_t tlen;
{
char *t, *lhs, *rhs;
int i, lhs_t, rhs_t, lhs_v, rhs_v, incr, lhs_l, rhs_l, width;
int i, lhs_t, rhs_t, incr, lhs_l, rhs_l, width;
intmax_t lhs_v, rhs_v;
intmax_t tl, tr;
char **result, *ep, *oep;

View File

@ -334,6 +334,7 @@ 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 ../pathnames.h
#evalstring.o: $(topdir)/y.tab.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

View File

@ -1,7 +1,7 @@
This file is cd.def, from which is created cd.c. It implements the
builtins "cd" and "pwd" in Bash.
Copyright (C) 1987-2009 Free Software Foundation, Inc.
Copyright (C) 1987-2010 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@ -58,7 +58,7 @@ extern int array_needs_making;
extern const char * const bash_getcwd_errstr;
static int bindpwd __P((int));
static void setpwd __P((char *));
static int setpwd __P((char *));
static char *resetpwd __P((char *));
static int change_to_directory __P((char *, int));
@ -67,9 +67,11 @@ int cdspelling = 0;
int cdable_vars;
static int eflag; /* file scope so bindpwd() can see it */
$BUILTIN cd
$FUNCTION cd_builtin
$SHORT_DOC cd [-L|-P] [dir]
$SHORT_DOC cd [-L|[-P [-e]]] [dir]
Change the shell working directory.
Change the current directory to DIR. The default DIR is the value of the
@ -88,15 +90,18 @@ Options:
-L force symbolic links to be followed
-P use the physical directory structure without following symbolic
links
-e if the -P option is supplied, and the current working directory
cannot be determined successfully, exit with a non-zero status
The default is to follow symbolic links, as if `-L' were specified.
Exit Status:
Returns 0 if the directory is changed; non-zero otherwise.
Returns 0 if the directory is changed, and if $PWD is set successfully when
-P is used; non-zero otherwise.
$END
/* Just set $PWD, don't change OLDPWD. Used by `pwd -P' in posix mode. */
static void
static int
setpwd (dirname)
char *dirname;
{
@ -105,11 +110,14 @@ setpwd (dirname)
old_anm = array_needs_making;
tvar = bind_variable ("PWD", dirname ? dirname : "", 0);
if (old_anm == 0 && array_needs_making && exported_p (tvar))
if (tvar && readonly_p (tvar))
return EXECUTION_FAILURE;
if (tvar && old_anm == 0 && array_needs_making && exported_p (tvar))
{
update_export_env_inplace ("PWD=", 4, dirname ? dirname : "");
array_needs_making = 0;
}
return EXECUTION_SUCCESS;
}
static int
@ -131,13 +139,19 @@ bindpwd (no_symlinks)
pwdvar = get_string_value ("PWD");
tvar = bind_variable ("OLDPWD", pwdvar, 0);
if (tvar && readonly_p (tvar))
r = EXECUTION_FAILURE;
if (old_anm == 0 && array_needs_making && exported_p (tvar))
{
update_export_env_inplace ("OLDPWD=", 7, pwdvar);
array_needs_making = 0;
}
setpwd (dirname);
if (setpwd (dirname) == EXECUTION_FAILURE)
r = EXECUTION_FAILURE;
if (dirname == 0 && eflag)
r = EXECUTION_FAILURE;
if (dirname && dirname != the_current_working_directory)
free (dirname);
@ -162,7 +176,7 @@ resetpwd (caller)
#define LCD_DOVARS 0x001
#define LCD_DOSPELL 0x002
#define LCD_PRINTPATH 0x004
#define LCD_FREEDIRNAME 0x010
#define LCD_FREEDIRNAME 0x008
/* This builtin is ultimately the way that all user-visible commands should
change the current working directory. It is called by cd_to_string (),
@ -183,6 +197,7 @@ cd_builtin (list)
}
#endif /* RESTRICTED_SHELL */
eflag = 0;
no_symlinks = no_symbolic_links;
reset_internal_getopt ();
while ((opt = internal_getopt (list, "LP")) != -1)
@ -195,6 +210,9 @@ cd_builtin (list)
case 'L':
no_symlinks = 0;
break;
case 'e':
eflag = 1;
break;
default:
builtin_usage ();
return (EXECUTION_FAILURE);
@ -204,6 +222,8 @@ cd_builtin (list)
lflag = (cdable_vars ? LCD_DOVARS : 0) |
((interactive && cdspelling) ? LCD_DOSPELL : 0);
if (eflag && no_symlinks == 0)
eflag = 0;
if (list == 0)
{
@ -270,6 +290,7 @@ cd_builtin (list)
free (temp);
}
#if 0 /* changed for bash-4.2 Posix cd description steps 5-6 */
/* POSIX.2 says that if `.' does not appear in $CDPATH, we don't
try the current directory, so we just punt now with an error
message if POSIXLY_CORRECT is non-zero. The check for cdpath[0]
@ -280,6 +301,7 @@ cd_builtin (list)
builtin_error ("%s: %s", dirname, strerror (ENOENT));
return (EXECUTION_FAILURE);
}
#endif
}
else
dirname = list->word->word;
@ -389,13 +411,14 @@ pwd_builtin (list)
if (directory)
{
opt = EXECUTION_SUCCESS;
printf ("%s\n", directory);
/* This is dumb but posix-mandated. */
if (posixly_correct && pflag)
setpwd (directory);
opt = setpwd (directory);
if (directory != the_current_working_directory)
free (directory);
return (sh_chkwrite (EXECUTION_SUCCESS));
return (sh_chkwrite (opt));
}
else
return (EXECUTION_FAILURE);

View File

@ -1,6 +1,6 @@
/* common.c - utility functions for all builtins */
/* Copyright (C) 1987-2009 Free Software Foundation, Inc.
/* Copyright (C) 1987-2010 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@ -151,7 +151,7 @@ builtin_usage ()
{
if (this_command_name && *this_command_name)
fprintf (stderr, _("%s: usage: "), this_command_name);
fprintf (stderr, "%s\n", current_builtin->short_doc);
fprintf (stderr, "%s\n", _(current_builtin->short_doc));
fflush (stderr);
}
@ -367,7 +367,7 @@ make_builtin_argv (list, ip)
return argv;
}
/* Remember LIST in $0 ... $9, and REST_OF_ARGS. If DESTRUCTIVE is
/* Remember LIST in $1 ... $9, and REST_OF_ARGS. If DESTRUCTIVE is
non-zero, then discard whatever the existing arguments are, else
only discard the ones that are to be replaced. */
void

View File

@ -1,6 +1,6 @@
/* common.h -- extern declarations for functions defined in common.c. */
/* Copyright (C) 1993-2004 Free Software Foundation, Inc.
/* Copyright (C) 1993-2010 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.

View File

@ -1,7 +1,7 @@
This file is complete.def, from which is created complete.c.
It implements the builtins "complete", "compgen", and "compopt" in Bash.
Copyright (C) 1999-2009 Free Software Foundation, Inc.
Copyright (C) 1999-2010 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@ -753,7 +753,7 @@ $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 currently being executed. If no OPTIONs are given, print
the completion options for each NAME or the current completion specification.
Options:

View File

@ -1,7 +1,7 @@
This file is declare.def, from which is created declare.c.
It implements the builtins "declare" and "local" in Bash.
Copyright (C) 1987-2009 Free Software Foundation, Inc.
Copyright (C) 1987-2010 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@ -22,7 +22,7 @@ $PRODUCES declare.c
$BUILTIN declare
$FUNCTION declare_builtin
$SHORT_DOC declare [-aAfFilrtux] [-p] [name[=value] ...]
$SHORT_DOC declare [-aAfFgilrtux] [-p] [name[=value] ...]
Set variable values and attributes.
Declare variables and give them attributes. If no NAMEs are given,
@ -32,6 +32,8 @@ 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)
-g create global variables when used in a shell function; otherwise
ignored
-p display the attributes and value of each NAME
Options which set attributes:
@ -50,7 +52,7 @@ Variables with the integer attribute have arithmetic evaluation (see
the `let' command) performed when the variable is assigned a value.
When used in a function, `declare' makes NAMEs local, as with the `local'
command.
command. The `-g' option suppresses this behavior.
Exit Status:
Returns success unless an invalid option is supplied or an error occurs.
@ -58,7 +60,7 @@ $END
$BUILTIN typeset
$FUNCTION declare_builtin
$SHORT_DOC typeset [-aAfFilrtux] [-p] name[=value] ...
$SHORT_DOC typeset [-aAfFgilrtux] [-p] name[=value] ...
Set variable values and attributes.
Obsolete. See `help declare'.
@ -125,9 +127,9 @@ local_builtin (list)
}
#if defined (ARRAY_VARS)
# define DECLARE_OPTS "+acfilprtuxAF"
# define DECLARE_OPTS "+acfgilprtuxAF"
#else
# define DECLARE_OPTS "+cfilprtuxF"
# define DECLARE_OPTS "+cfgilprtuxF"
#endif
/* The workhorse function. */
@ -137,12 +139,12 @@ declare_internal (list, local_var)
int local_var;
{
int flags_on, flags_off, *flags;
int any_failed, assign_error, pflag, nodefs, opt;
int any_failed, assign_error, pflag, nodefs, opt, mkglobal;
char *t, *subscript_start;
SHELL_VAR *var;
FUNCTION_DEF *shell_fn;
flags_on = flags_off = any_failed = assign_error = pflag = nodefs = 0;
flags_on = flags_off = any_failed = assign_error = pflag = nodefs = mkglobal = 0;
reset_internal_getopt ();
while ((opt = internal_getopt (list, DECLARE_OPTS)) != EOF)
{
@ -177,6 +179,10 @@ declare_internal (list, local_var)
case 'f':
*flags |= att_function;
break;
case 'g':
if (flags == &flags_on)
mkglobal = 1;
break;
case 'i':
*flags |= att_integer;
break;
@ -328,7 +334,7 @@ declare_internal (list, local_var)
/* XXX - this has consequences when we're making a local copy of a
variable that was in the temporary environment. Watch out
for this. */
if (variable_context && ((flags_on & att_function) == 0))
if (variable_context && mkglobal == 0 && ((flags_on & att_function) == 0))
{
#if defined (ARRAY_VARS)
if (flags_on & att_assoc)
@ -410,7 +416,7 @@ declare_internal (list, local_var)
{
/* Non-null if we just created or fetched a local variable. */
if (var == 0)
var = find_variable (name);
var = mkglobal ? find_global_variable (name) : find_variable (name);
if (var == 0)
{

View File

@ -70,6 +70,7 @@ extern int posixly_correct;
extern int indirection_level, subshell_environment;
extern int return_catch_flag, return_catch_value;
extern int last_command_exit_value;
extern int executing_command_builtin;
/* How many `levels' of sourced files we have. */
int sourcelevel = 0;
@ -148,10 +149,6 @@ file_error_and_exit:
return ((flags & FEVAL_BUILTIN) ? EXECUTION_FAILURE : -1);
}
#if defined (__CYGWIN__) && defined (O_TEXT)
setmode (fd, O_TEXT);
#endif
if (S_ISREG (finfo.st_mode) && file_size <= SSIZE_MAX)
{
string = (char *)xmalloc (1 + file_size);
@ -342,7 +339,7 @@ source_file (filename, sflags)
if (sflags)
flags |= FEVAL_NOPUSHARGS;
/* POSIX shells exit if non-interactive and file error. */
if (posixly_correct && !interactive_shell)
if (posixly_correct && interactive_shell == 0 && executing_command_builtin == 0)
flags |= FEVAL_LONGJMP;
rval = _evalfile (filename, flags);

View File

@ -1,6 +1,6 @@
/* evalstring.c - evaluate a string as one or more shell commands.
/* evalstring.c - evaluate a string as one or more shell commands. */
/* Copyright (C) 1996-2009 Free Software Foundation, Inc.
/* Copyright (C) 1996-2010 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@ -331,13 +331,9 @@ parse_and_execute (string, from_file, flags)
(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

View File

@ -1,7 +1,7 @@
This file is exec.def, from which is created exec.c.
It implements the builtin "exec" in Bash.
Copyright (C) 1987-2009 Free Software Foundation, Inc.
Copyright (C) 1987-2010 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@ -76,6 +76,7 @@ extern int errno;
extern int subshell_environment;
extern REDIRECT *redirection_undo_list;
extern char *exec_argv0;
int no_exit_on_failed_exec;
@ -102,7 +103,7 @@ exec_builtin (list)
char *argv0, *command, **args, **env, *newname, *com2;
cleanenv = login = 0;
argv0 = (char *)NULL;
exec_argv0 = argv0 = (char *)NULL;
reset_internal_getopt ();
while ((opt = internal_getopt (list, "cla:")) != -1)
@ -147,8 +148,20 @@ exec_builtin (list)
if (command == 0)
{
sh_notfound (args[0]);
exit_value = EX_NOTFOUND; /* As per Posix.2, 3.14.6 */
if (file_isdir (args[0]))
{
#if defined (EISDIR)
builtin_error (_("%s: cannot execute: %s"), args[0], strerror (EISDIR));
#else
builtin_error (_("%s: cannot execute: %s"), args[0], strerror (errno));
#endif
exit_value = EX_NOEXEC;
}
else
{
sh_notfound (args[0]);
exit_value = EX_NOTFOUND; /* As per Posix.2, 3.14.6 */
}
goto failed_exec;
}
@ -164,6 +177,7 @@ exec_builtin (list)
{
free (args[0]);
args[0] = login ? mkdashname (argv0) : savestring (argv0);
exec_argv0 = savestring (args[0]);
}
else if (login)
{
@ -198,7 +212,7 @@ exec_builtin (list)
end_job_control ();
#endif /* JOB_CONTROL */
shell_execve (command, args, env);
exit_value = shell_execve (command, args, env);
/* We have to set this to NULL because shell_execve has called realloc()
to stuff more items at the front of the array, which may have caused
@ -207,7 +221,9 @@ exec_builtin (list)
if (cleanenv == 0)
adjust_shell_level (1);
if (executable_file (command) == 0)
if (exit_value == EX_NOTFOUND) /* no duplicate error message */
goto failed_exec;
else if (executable_file (command) == 0)
{
builtin_error (_("%s: cannot execute: %s"), command, strerror (errno));
exit_value = EX_NOEXEC; /* As per Posix.2, 3.14.6 */

View File

@ -1,7 +1,7 @@
This file is fc.def, from which is created fc.c.
It implements the builtin "fc" in Bash.
Copyright (C) 1987-2009 Free Software Foundation, Inc.
Copyright (C) 1987-2010 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@ -85,7 +85,7 @@ $END
extern int errno;
#endif /* !errno */
extern int current_command_line_count;
extern int current_command_line_count, saved_command_line_count;
extern int literal_history;
extern int posixly_correct;
extern int subshell_environment, interactive_shell;
@ -304,7 +304,7 @@ fc_builtin (list)
last_hist = i - rh - hist_last_line_added;
/* XXX */
if (i == last_hist && hlist[last_hist] == 0)
if (saved_command_line_count > 0 && i == last_hist && hlist[last_hist] == 0)
while (last_hist >= 0 && hlist[last_hist] == 0)
last_hist--;
if (last_hist < 0)
@ -475,7 +475,7 @@ fc_gethnum (command, hlist)
HIST_ENTRY **hlist;
{
int sign, n, clen, rh;
register int i, j, last_hist;
register int i, j;
register char *s;
sign = 1;
@ -495,15 +495,7 @@ fc_gethnum (command, hlist)
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 (i == last_hist && hlist[last_hist] == 0)
while (last_hist >= 0 && hlist[last_hist] == 0)
last_hist--;
if (last_hist < 0)
return (-1);
i = last_hist;
i -= rh + hist_last_line_added;
/* No specification defaults to most recent command. */
if (command == NULL)

View File

@ -108,7 +108,9 @@ getopts_bind_variable (name, value)
if (legal_identifier (name))
{
v = bind_variable (name, value, 0);
return (v && (readonly_p (v) == 0)) ? EXECUTION_SUCCESS : EXECUTION_FAILURE;
if (v && (readonly_p (v) || noassign_p (v)))
return (EX_MISCERROR);
return (v ? EXECUTION_SUCCESS : EXECUTION_FAILURE);
}
else
{

View File

@ -1,7 +1,7 @@
This file is hash.def, from which is created hash.c.
It implements the builtin "hash" in Bash.
Copyright (C) 1987-2009 Free Software Foundation, Inc.
Copyright (C) 1987-2010 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@ -159,7 +159,9 @@ hash_builtin (list)
{
/* Add, remove or rehash the specified commands. */
w = list->word->word;
if (pathname)
if (absolute_program (w))
continue;
else if (pathname)
{
if (is_directory (pathname))
{
@ -173,8 +175,6 @@ hash_builtin (list)
else
phash_insert (w, pathname, 0, 0);
}
else if (absolute_program (w))
continue;
else if (delete)
{
if (phash_remove (w))
@ -202,6 +202,7 @@ add_hashed_command (w, quiet)
rv = 0;
if (find_function (w) == 0 && find_shell_builtin (w) == 0)
{
phash_remove (w);
full_path = find_user_command (w);
if (full_path && executable_file (full_path))
phash_insert (w, full_path, dot_found_in_search, 0);

View File

@ -155,7 +155,7 @@ help_builtin (list)
continue;
}
printf ("%s: %s\n", name, shell_builtins[i].short_doc);
printf ("%s: %s\n", name, _(shell_builtins[i].short_doc));
if (sflag == 0)
show_longdoc (i);
@ -288,7 +288,7 @@ show_manpage (name, i)
/* SYNOPSIS */
printf ("SYNOPSIS\n");
printf ("%*s%s\n\n", BASE_INDENT, " ", shell_builtins[i].short_doc);
printf ("%*s%s\n\n", BASE_INDENT, " ", _(shell_builtins[i].short_doc));
/* DESCRIPTION */
printf ("DESCRIPTION\n");
@ -360,7 +360,7 @@ A star (*) next to a name means that the command is disabled.\n\
/* first column */
blurb[0] = (shell_builtins[i].flags & BUILTIN_ENABLED) ? ' ' : '*';
strncpy (blurb + 1, shell_builtins[i].short_doc, width - 2);
strncpy (blurb + 1, _(shell_builtins[i].short_doc), width - 2);
blurb[width - 2] = '>'; /* indicate truncation */
blurb[width - 1] = '\0';
printf ("%s", blurb);
@ -376,7 +376,7 @@ A star (*) next to a name means that the command is disabled.\n\
/* second column */
blurb[0] = (shell_builtins[i+height].flags & BUILTIN_ENABLED) ? ' ' : '*';
strncpy (blurb + 1, shell_builtins[i+height].short_doc, width - 3);
strncpy (blurb + 1, _(shell_builtins[i+height].short_doc), width - 3);
blurb[width - 3] = '>'; /* indicate truncation */
blurb[width - 2] = '\0';
printf ("%s\n", blurb);

View File

@ -1,7 +1,7 @@
This file is kill.def, from which is created kill.c.
It implements the builtin "kill" in Bash.
Copyright (C) 1987-2009 Free Software Foundation, Inc.
Copyright (C) 1987-2010 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@ -121,9 +121,7 @@ kill_builtin (list)
else
sig = decode_signal (sigspec, dflags);
list = list->next;
#if 0
saw_signal++; /* XXX - for bash-4.2 */
#endif
saw_signal++;
}
else
{

View File

@ -61,7 +61,7 @@ parentheses are evaluated first and may override the precedence
rules above.
Exit Status:
If the last ARG evaluates to 0, let returns 1; let returns 0 otherwise..
If the last ARG evaluates to 0, let returns 1; let returns 0 otherwise.
$END
#include <config.h>

View File

@ -2,7 +2,7 @@ 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.
Copyright (C) 2008-2010 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@ -44,7 +44,8 @@ Arguments:
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.
element to be assigned and the line to be assigned to that element
as additional arguments.
If not supplied with an explicit origin, mapfile will clear ARRAY before
assigning to it.
@ -88,7 +89,10 @@ extern int errno;
#if defined (ARRAY_VARS)
static int run_callback __P((const char *, unsigned int, const char *));
#define DEFAULT_ARRAY_NAME "MAPFILE"
#define DEFAULT_VARIABLE_NAME "MAPLINE" /* not used right now */
/* The value specifying how frequently `mapfile' calls the callback. */
#define DEFAULT_QUANTUM 5000
@ -98,18 +102,20 @@ extern int errno;
#define MAPF_CHOP 0x02
static int
run_callback(callback, current_index)
run_callback (callback, curindex, curline)
const char *callback;
unsigned int current_index;
unsigned int curindex;
const char *curline;
{
unsigned int execlen;
char *execstr;
char *execstr, *qline;
int flags;
execlen = strlen (callback) + 10;
/* 1 for space between %s and %d,
qline = sh_single_quote (curline);
execlen = strlen (callback) + strlen (qline) + 10;
/* 1 for each space between %s and %d,
another 1 for the last nul char for C string. */
execlen += 2;
execlen += 3;
execstr = xmalloc (execlen);
flags = SEVAL_NOHIST;
@ -117,8 +123,9 @@ run_callback(callback, current_index)
if (interactive)
flags |= SEVAL_INTERACT;
#endif
snprintf (execstr, execlen, "%s %d", callback, current_index);
return parse_and_execute(execstr, NULL, flags);
snprintf (execstr, execlen, "%s %d %s", callback, curindex, qline);
free (qline);
return parse_and_execute (execstr, NULL, flags);
}
static void
@ -202,7 +209,7 @@ mapfile (fd, line_count_goal, origin, nskip, callback_quantum, callback, array_n
/* 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);
run_callback (callback, array_index, line);
/* Reset the buffer for bash own stream. */
if (unbuffered_read == 0)

View File

@ -1,7 +1,7 @@
/* mkbuiltins.c - Create builtins.c, builtext.h, and builtdoc.c from
a single source file called builtins.def. */
/* Copyright (C) 1987-2009 Free Software Foundation, Inc.
/* Copyright (C) 1987-2010 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@ -1127,7 +1127,7 @@ char *structfile_header[] = {
};
char *structfile_footer[] = {
" { (char *)0x0, (sh_builtin_func_t *)0x0, 0, (char **)0x0, (char *)0x0 }",
" { (char *)0x0, (sh_builtin_func_t *)0x0, 0, (char **)0x0, (char *)0x0, (char *)0x0 }",
"};",
"",
"struct builtin *shell_builtins = static_shell_builtins;",
@ -1380,7 +1380,7 @@ write_documentation (stream, documentation, indentation, flags)
{
register int i, j;
register char *line;
int string_array, texinfo, base_indent, last_cpp, filename_p;
int string_array, texinfo, base_indent, filename_p;
if (stream == 0)
return;
@ -1407,7 +1407,7 @@ write_documentation (stream, documentation, indentation, flags)
base_indent = (string_array && single_longdoc_strings && filename_p == 0) ? BASE_INDENT : 0;
for (i = last_cpp = 0, texinfo = (flags & TEXINFO); line = documentation[i]; i++)
for (i = 0, texinfo = (flags & TEXINFO); line = documentation[i]; i++)
{
/* Allow #ifdef's to be written out verbatim, but don't put them into
separate help files. */
@ -1415,11 +1415,8 @@ write_documentation (stream, documentation, indentation, flags)
{
if (string_array && filename_p == 0 && single_longdoc_strings == 0)
fprintf (stream, "%s\n", line);
last_cpp = 1;
continue;
}
else
last_cpp = 0;
/* prefix with N_( for gettext */
if (string_array && single_longdoc_strings == 0)

View File

@ -1,7 +1,7 @@
This file is printf.def, from which is created printf.c.
It implements the builtin "printf" in Bash.
Copyright (C) 1997-2009 Free Software Foundation, Inc.
Copyright (C) 1997-2010 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@ -40,6 +40,8 @@ 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
%(fmt)T output the date-time string resulting from using FMT as a format
string for strftime(3)
Exit Status:
Returns success unless an invalid option is given or a write or assignment
@ -72,9 +74,12 @@ $END
# include <inttypes.h>
#endif
#include "posixtime.h"
#include "../bashansi.h"
#include "../bashintl.h"
#define NEED_STRFTIME_DECL
#include "../shell.h"
#include "shmbutil.h"
#include "stdc.h"
@ -167,6 +172,8 @@ extern int errno;
#define SKIP1 "#'-+ 0"
#define LENMODS "hjlLtz"
extern time_t shell_start_time;
#if !HAVE_ASPRINTF
extern int asprintf __P((char **, const char *, ...)) __attribute__((__format__ (printf, 2, 3)));
#endif
@ -177,7 +184,7 @@ extern int vsnprintf __P((char *, size_t, const char *, va_list)) __attribute__(
static void printf_erange __P((char *));
static int printstr __P((char *, char *, int, int, int));
static int tescape __P((char *, char *, int *));
static int tescape __P((char *, char *, int *, 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)));
@ -224,6 +231,10 @@ printf_builtin (list)
int ch, fieldwidth, precision;
int have_fieldwidth, have_precision;
char convch, thisch, nextch, *format, *modstart, *fmt, *start;
#if defined (HANDLE_MULTIBYTE)
char mbch[25]; /* 25 > MB_LEN_MAX, plus can handle 4-byte UTF-8 and large Unicode characters*/
int mbind, mblen;
#endif
conversion_error = 0;
retval = EXECUTION_SUCCESS;
@ -301,8 +312,17 @@ printf_builtin (list)
fmt++;
/* A NULL third argument to tescape means to bypass the
special processing for arguments to %b. */
fmt += tescape (fmt, &nextch, (int *)NULL);
#if defined (HANDLE_MULTIBYTE)
/* Accommodate possible use of \u or \U, which can result in
multibyte characters */
memset (mbch, '\0', sizeof (mbch));
fmt += tescape (fmt, mbch, &mblen, (int *)NULL);
for (mbind = 0; mbind < mblen; mbind++)
PC (mbch[mbind]);
#else
fmt += tescape (fmt, &nextch, (int *)NULL, (int *)NULL);
PC (nextch);
#endif
fmt--; /* for loop will increment it for us again */
continue;
}
@ -401,6 +421,70 @@ printf_builtin (list)
break;
}
case '(':
{
char *timefmt, timebuf[128], *t;
int n;
intmax_t arg;
time_t secs;
struct tm *tm;
modstart[1] = nextch; /* restore char after left paren */
timefmt = xmalloc (strlen (fmt) + 3);
fmt++; /* skip over left paren */
for (t = timefmt, n = 1; *fmt; )
{
if (*fmt == '(')
n++;
else if (*fmt == ')')
n--;
if (n == 0)
break;
*t++ = *fmt++;
}
*t = '\0';
if (*++fmt != 'T')
{
builtin_warning (_("`%c': invalid time format specification"), *fmt);
fmt = start;
free (timefmt);
PC (*fmt);
continue;
}
if (timefmt[0] == '\0')
{
timefmt[0] = '%';
timefmt[1] = 'X'; /* locale-specific current time - should we use `+'? */
timefmt[2] = '\0';
}
/* argument is seconds since the epoch with special -1 and -2 */
arg = getintmax ();
if (arg == -1)
secs = NOW; /* roughly date +%s */
else if (arg == -2)
secs = shell_start_time; /* roughly $SECONDS */
else
secs = arg;
tm = localtime (&secs);
n = strftime (timebuf, sizeof (timebuf), timefmt, tm);
free (timefmt);
if (n == 0)
timebuf[0] = '\0';
else
timebuf[sizeof(timebuf) - 1] = '\0';
/* convert to %s format that preserves fieldwidth and precision */
modstart[0] = 's';
modstart[1] = '\0';
n = printstr (start, timebuf, strlen (timebuf), fieldwidth, precision); /* XXX - %s for now */
if (n < 0)
{
sh_wrerror ();
clearerr (stdout);
PRETURN (EXECUTION_FAILURE);
}
break;
}
case 'n':
{
char *var;
@ -699,15 +783,18 @@ printstr (fmt, string, len, fieldwidth, precision)
do the \c short-circuiting, and \c is treated as an unrecognized escape
sequence; we also bypass the other processing specific to %b arguments. */
static int
tescape (estart, cp, sawc)
tescape (estart, cp, lenp, sawc)
char *estart;
char *cp;
int *sawc;
int *lenp, *sawc;
{
register char *p;
int temp, c, evalue;
unsigned long uvalue;
p = estart;
if (lenp)
*lenp = 1;
switch (c = *p++)
{
@ -743,14 +830,10 @@ tescape (estart, cp, sawc)
*cp = evalue & 0xFF;
break;
/* And, as another extension, we allow \xNNN, where each N is a
/* And, as another extension, we allow \xNN, where each N is a
hex digit. */
case 'x':
#if 0
for (evalue = 0; ISXDIGIT ((unsigned char)*p); p++)
#else
for (temp = 2, evalue = 0; ISXDIGIT ((unsigned char)*p) && temp--; p++)
#endif
evalue = (evalue * 16) + HEXVALUE (*p);
if (p == estart + 1)
{
@ -761,6 +844,30 @@ tescape (estart, cp, sawc)
*cp = evalue & 0xFF;
break;
#if defined (HANDLE_MULTIBYTE)
case 'u':
case 'U':
temp = (c == 'u') ? 4 : 8; /* \uNNNN \UNNNNNNNN */
for (uvalue = 0; ISXDIGIT ((unsigned char)*p) && temp--; p++)
uvalue = (uvalue * 16) + HEXVALUE (*p);
if (p == estart + 1)
{
builtin_error (_("missing unicode digit for \\%c"), c);
*cp = '\\';
return 0;
}
if (uvalue <= UCHAR_MAX)
*cp = uvalue;
else
{
temp = u32cconv (uvalue, cp);
cp[temp] = '\0';
if (lenp)
*lenp = temp;
}
break;
#endif
case '\\': /* \\ -> \ */
*cp = c;
break;
@ -799,12 +906,12 @@ bexpand (string, len, sawc, lenp)
{
int temp;
char *ret, *r, *s, c;
#if 0
if (string == 0 || *string == '\0')
#else
if (string == 0 || len == 0)
#if defined (HANDLE_MULTIBYTE)
char mbch[25];
int mbind, mblen;
#endif
if (string == 0 || len == 0)
{
if (sawc)
*sawc = 0;
@ -823,7 +930,12 @@ bexpand (string, len, sawc, lenp)
continue;
}
temp = 0;
s += tescape (s, &c, &temp);
#if defined (HANDLE_MULTIBYTE)
memset (mbch, '\0', sizeof (mbch));
s += tescape (s, mbch, &mblen, &temp);
#else
s += tescape (s, &c, (int *)NULL, &temp);
#endif
if (temp)
{
if (sawc)
@ -831,7 +943,12 @@ bexpand (string, len, sawc, lenp)
break;
}
#if defined (HANDLE_MULTIBYTE)
for (mbind = 0; mbind < mblen; mbind++)
*r++ = mbch[mbind];
#else
*r++ = c;
#endif
}
*r = '\0';

View File

@ -1,7 +1,7 @@
This file is read.def, from which is created read.c.
It implements the builtin "read" in Bash.
Copyright (C) 1987-2009 Free Software Foundation, Inc.
Copyright (C) 1987-2010 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@ -793,11 +793,16 @@ assign_vars:
}
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);
{
stupidly_hack_special_variables (list->word->word);
VUNSETATTR (var, att_invisible);
}
else
retval = EXECUTION_FAILURE;
FREE (tofree);
xfree (orig_input_string);
return (retval);
@ -807,14 +812,17 @@ static SHELL_VAR *
bind_read_variable (name, value)
char *name, *value;
{
SHELL_VAR *v;
#if defined (ARRAY_VARS)
if (valid_array_reference (name) == 0)
return (bind_variable (name, value, 0));
v = bind_variable (name, value, 0);
else
return (assign_array_element (name, value, 0));
v = assign_array_element (name, value, 0);
#else /* !ARRAY_VARS */
return bind_variable (name, value, 0);
v = bind_variable (name, value, 0);
#endif /* !ARRAY_VARS */
return (v == 0 ? v
: ((readonly_p (v) || noassign_p (v)) ? (SHELL_VAR *)NULL : v));
}
#if defined (HANDLE_MULTIBYTE)

View File

@ -59,7 +59,7 @@ extern int no_line_editing;
$BUILTIN set
$FUNCTION set_builtin
$SHORT_DOC set [--abefhkmnptuvxBCHP] [-o option-name] [arg ...]
$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
@ -138,6 +138,9 @@ Options:
-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.
If there are no remaining arguments, the positional parameters
are unset.
- Assign any remaining arguments to the positional parameters.
The -x and -v options are turned off.

View File

@ -1,7 +1,7 @@
This file is setattr.def, from which is created setattr.c.
It implements the builtins "export" and "readonly", in Bash.
Copyright (C) 1987-2009 Free Software Foundation, Inc.
Copyright (C) 1987-2010 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@ -82,7 +82,7 @@ export_builtin (list)
$BUILTIN readonly
$FUNCTION readonly_builtin
$SHORT_DOC readonly [-af] [name[=value] ...] or readonly -p
$SHORT_DOC readonly [-aAf] [name[=value] ...] or readonly -p
Mark shell variables as unchangeable.
Mark each NAME as read-only; the values of these NAMEs may not be
@ -433,11 +433,11 @@ show_var_attributes (var, pattr, nodefs)
printf ("%s\n", var->name);
else if (function_p (var))
printf ("%s\n", named_function_string (var->name, function_cell (var), FUNC_MULTILINE|FUNC_EXTERNAL));
else if (invisible_p (var))
else if (invisible_p (var) || var_isset (var) == 0)
printf ("%s\n", var->name);
else
{
x = sh_double_quote (var_isset (var) ? value_cell (var) : "");
x = sh_double_quote (value_cell (var));
printf ("%s=%s\n", var->name, x);
free (x);
}

View File

@ -1,7 +1,7 @@
This file is shopt.def, from which is created shopt.c.
It implements the Bash `shopt' builtin.
Copyright (C) 1994-2009 Free Software Foundation, Inc.
Copyright (C) 1994-2010 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@ -84,6 +84,7 @@ extern int gnu_error_format;
extern int check_jobs_at_exit;
extern int autocd;
extern int glob_star;
extern int lastpipe_opt;
#if defined (EXTENDED_GLOB)
extern int extended_glob;
@ -124,6 +125,7 @@ static int shopt_login_shell;
static int shopt_compat31;
static int shopt_compat32;
static int shopt_compat40;
static int shopt_compat41;
typedef int shopt_set_func_t __P((char *, int));
@ -146,6 +148,7 @@ static struct {
{ "compat31", &shopt_compat31, set_compatibility_level },
{ "compat32", &shopt_compat32, set_compatibility_level },
{ "compat40", &shopt_compat40, set_compatibility_level },
{ "compat41", &shopt_compat41, set_compatibility_level },
#if defined (READLINE)
{ "dirspell", &dircomplete_spelling, (shopt_set_func_t *)NULL },
#endif
@ -175,6 +178,7 @@ static struct {
#endif
{ "huponexit", &hup_on_exit, (shopt_set_func_t *)NULL },
{ "interactive_comments", &interactive_comments, set_shellopts_after_change },
{ "lastpipe", &lastpipe_opt, (shopt_set_func_t *)NULL },
#if defined (HISTORY)
{ "lithist", &literal_history, (shopt_set_func_t *)NULL },
#endif

View File

@ -80,6 +80,8 @@ extern int errno;
#endif /* !errno */
extern int posixly_correct;
extern int last_command_exit_value;
extern int executing_command_builtin;
static void maybe_pop_dollar_vars __P((void));
@ -151,6 +153,11 @@ source_builtin (list)
if (source_searches_cwd == 0)
{
builtin_error (_("%s: file not found"), list->word->word);
if (posixly_correct && interactive_shell == 0 && executing_command_builtin == 0)
{
last_command_exit_value = 1;
jump_to_top_level (EXITPROG);
}
return (EXECUTION_FAILURE);
}
else

View File

@ -1,7 +1,7 @@
This file is test.def, from which is created test.c.
It implements the builtin "test" in Bash.
Copyright (C) 1987-2009 Free Software Foundation, Inc.
Copyright (C) 1987-2010 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@ -28,7 +28,10 @@ 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
are string operators as well, and numeric comparison operators.
are string operators and numeric comparison operators as well.
The behavior of test depends on the number of arguments. Read the
bash manual page for the complete specification.
File operators:
@ -80,6 +83,7 @@ String operators:
Other operators:
-o OPTION True if the shell option OPTION is enabled.
-v VAR True if the shell variable VAR is set
! 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.

View File

@ -1,7 +1,7 @@
This file is trap.def, from which is created trap.c.
It implements the builtin "trap" in Bash.
Copyright (C) 1987-2009 Free Software Foundation, Inc.
Copyright (C) 1987-2010 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@ -35,7 +35,11 @@ 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) ARG is executed on exit from the shell. If
a SIGNAL_SPEC is DEBUG, ARG is executed before every simple command.
a SIGNAL_SPEC is DEBUG, ARG is executed before every simple command. If
a SIGNAL_SPEC is RETURN, ARG is executed each time a shell function or a
script run by the . or source builtins finishes executing. A SIGNAL_SPEC
of ERR means to execute ARG each time a command's failure would cause the
shell to exit when the -e option is enabled.
If no arguments are supplied, trap prints the list of commands associated
with each signal.
@ -93,7 +97,7 @@ static int display_traps __P((WORD_LIST *));
#define REVERT 1 /* Revert to this signals original value. */
#define IGNORE 2 /* Ignore this signal. */
extern int posixly_correct;
extern int posixly_correct, subshell_environment;
int
trap_builtin (list)
@ -103,6 +107,7 @@ trap_builtin (list)
list_signal_names = display = 0;
result = EXECUTION_SUCCESS;
reset_internal_getopt ();
while ((opt = internal_getopt (list, "lp")) != -1)
{
@ -126,7 +131,11 @@ trap_builtin (list)
if (list_signal_names)
return (sh_chkwrite (display_signal_list ((WORD_LIST *)NULL, 1)));
else if (display || list == 0)
return (sh_chkwrite (display_traps (list)));
{
initialize_terminating_signals ();
get_all_original_signals ();
return (sh_chkwrite (display_traps (list)));
}
else
{
char *first_arg;
@ -163,6 +172,16 @@ trap_builtin (list)
operation = REVERT;
}
/* If we're in a command substitution, we haven't freed the trap strings
(though we reset the signal handlers). If we're setting a trap to
handle a signal here, free the rest of the trap strings since they
don't apply any more. */
if (subshell_environment & SUBSHELL_RESETTRAP)
{
free_trap_strings ();
subshell_environment &= ~SUBSHELL_RESETTRAP;
}
while (list)
{
sig = decode_signal (list->word->word, opt);
@ -188,6 +207,8 @@ trap_builtin (list)
switch (sig)
{
case SIGINT:
/* XXX - should we do this if original disposition
was SIG_IGN? */
if (interactive)
set_signal_handler (SIGINT, sigint_sighandler);
else
@ -229,10 +250,13 @@ showtrap (i)
char *t, *p, *sn;
p = trap_list[i];
if (p == (char *)DEFAULT_SIG)
if (p == (char *)DEFAULT_SIG && signal_is_hard_ignored (i) == 0)
return;
else if (signal_is_hard_ignored (i))
t = (char *)NULL;
else
t = (p == (char *)IGNORE_SIG) ? (char *)NULL : sh_single_quote (p);
t = (p == (char *)IGNORE_SIG) ? (char *)NULL : sh_single_quote (p);
sn = signal_name (i);
/* Make sure that signals whose names are unknown (for whatever reason)
are printed as signal numbers. */

View File

@ -1,7 +1,7 @@
This file is ulimit.def, from which is created ulimit.c.
It implements the builtin "ulimit" in Bash.
Copyright (C) 1987-2009 Free Software Foundation, Inc.
Copyright (C) 1987-2010 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@ -118,6 +118,10 @@ extern int errno;
# undef HAVE_RESOURCE
#endif
#if !defined (HAVE_RESOURCE) && defined (HAVE_ULIMIT_H)
# include <ulimit.h>
#endif
#if !defined (RLIMTYPE)
# define RLIMTYPE long
# define string_to_rlimtype(s) strtol(s, (char **)NULL, 10)

View File

@ -1,7 +1,7 @@
/* command.h -- The structures used internally to represent commands, and
the extern declarations of the functions used to create them. */
/* Copyright (C) 1993-2009 Free Software Foundation, Inc.
/* Copyright (C) 1993-2010 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@ -96,6 +96,7 @@ enum command_type { cm_for, cm_case, cm_while, cm_if, cm_simple, cm_select,
#define W_NOPROCSUB 0x100000 /* don't perform process substitution */
#define W_HASCTLESC 0x200000 /* word contains literal CTLESC characters */
#define W_ASSIGNASSOC 0x400000 /* word looks like associative array assignment */
#define W_ARRAYIND 0x800000 /* word is an array index being expanded */
/* Possible values for subshell_environment */
#define SUBSHELL_ASYNC 0x01 /* subshell caused by `command &' */
@ -105,6 +106,7 @@ enum command_type { cm_for, cm_case, cm_while, cm_if, cm_simple, cm_select,
#define SUBSHELL_PIPE 0x10 /* subshell from a pipeline element */
#define SUBSHELL_PROCSUB 0x20 /* subshell caused by <(command) or >(command) */
#define SUBSHELL_COPROC 0x40 /* subshell from a coproc pipeline */
#define SUBSHELL_RESETTRAP 0x80 /* subshell needs to reset trap strings on first call to trap */
/* A structure which represents a word. */
typedef struct word_desc {
@ -168,6 +170,7 @@ typedef struct element {
#define CMD_STDIN_REDIR 0x400 /* async command needs implicit </dev/null */
#define CMD_COMMAND_BUILTIN 0x0800 /* command executed by `command' builtin */
#define CMD_COPROC_SUBSHELL 0x1000
#define CMD_LASTPIPE 0x2000
/* What a command looks like. */
typedef struct command {

View File

@ -215,6 +215,9 @@
/* The number of bytes in a double (hopefully 8). */
#undef SIZEOF_DOUBLE
/* The number of bytes in an `intmax_t'. */
#undef SIZEOF_INTMAX_T
/* The number of bytes in a `long long', if we have one. */
#undef SIZEOF_LONG_LONG
@ -415,6 +418,8 @@
#undef HAVE_STRUCT_TIMEZONE
#undef WEXITSTATUS_OFFSET
/* Characteristics of definitions in the system header files. */
#undef HAVE_GETPW_DECLS
@ -546,18 +551,21 @@
/* Define if you don't have vprintf but do have _doprnt. */
#undef HAVE_DOPRNT
/* Define if you have the dprintf function. */
#undef HAVE_DPRINTF
/* Define if you have the dup2 function. */
#undef HAVE_DUP2
/* Define if you have the eaccess function. */
#undef HAVE_EACCESS
/* Define if you have the faccessat function. */
#undef HAVE_FACCESSAT
/* Define if you have the fcntl function. */
#undef HAVE_FCNTL
/* Define if you have the fdprintf function. */
#undef HAVE_FDPRINTF
/* Define if you have the fpurge/__fpurge function. */
#undef HAVE_FPURGE
#undef HAVE___FPURGE
@ -680,6 +688,9 @@
/* Define if you have the mbscmp function. */
#undef HAVE_MBSCMP
/* Define if you have the mbsnrtowcs function. */
#undef HAVE_MBSNRTOWCS
/* Define if you have the mbsrtowcs function. */
#undef HAVE_MBSRTOWCS
@ -762,6 +773,9 @@
/* Define if you have the strchr function. */
#undef HAVE_STRCHR
/* Define if you have the strchrnul function. */
#undef HAVE_STRCHRNUL
/* Define if you have the strcoll function. */
#undef HAVE_STRCOLL
@ -867,6 +881,9 @@
/* Define if you have the wctype function. */
#undef HAVE_WCTYPE
/* Define if you have the wcswidth function. */
#undef HAVE_WCSWIDTH
/* Define if you have the wcwidth function. */
#undef HAVE_WCWIDTH
@ -994,6 +1011,9 @@
/* Define if you have the <termios.h> header file. */
#undef HAVE_TERMIOS_H
/* Define if you have the <ulimit.h> header file. */
#undef HAVE_ULIMIT_H
/* Define if you have the <unistd.h> header file. */
#undef HAVE_UNISTD_H

886
configure vendored

File diff suppressed because it is too large Load Diff

View File

@ -1,11 +1,11 @@
dnl
dnl Configure script for bash-4.1
dnl Configure script for bash-4.2
dnl
dnl report bugs to chet@po.cwru.edu
dnl
dnl Process this file with autoconf to produce a configure script.
# Copyright (C) 1987-2009 Free Software Foundation, Inc.
# Copyright (C) 1987-2011 Free Software Foundation, Inc.
#
# This program is free software: you can redistribute it and/or modify
@ -21,9 +21,9 @@ dnl Process this file with autoconf to produce a configure script.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
AC_REVISION([for Bash 4.1, version 4.019])dnl
AC_REVISION([for Bash 4.2, version 4.037])dnl
define(bashvers, 4.1)
define(bashvers, 4.2)
define(relstatus, release)
AC_INIT([bash], bashvers-relstatus, [bug-bash@gnu.org])
@ -98,7 +98,7 @@ esac
dnl
dnl macros for the bash debugger
dnl
AM_PATH_LISPDIR
dnl AM_PATH_LISPDIR
AC_ARG_VAR(DEBUGGER_START_FILE, [location of bash debugger initialization file])
dnl arguments to configure
@ -659,7 +659,7 @@ BASH_HEADER_INTTYPES
AC_CHECK_HEADERS(unistd.h stdlib.h stdarg.h varargs.h limits.h string.h \
memory.h locale.h termcap.h termio.h termios.h dlfcn.h \
stddef.h stdint.h netdb.h pwd.h grp.h strings.h regex.h \
syslog.h)
syslog.h ulimit.h)
AC_CHECK_HEADERS(sys/pte.h sys/stream.h sys/select.h sys/file.h \
sys/resource.h sys/param.h sys/socket.h sys/stat.h \
sys/time.h sys/times.h sys/types.h sys/wait.h)
@ -727,7 +727,7 @@ AC_CHECK_FUNCS(dup2 eaccess fcntl getdtablesize getgroups gethostname \
AC_REPLACE_FUNCS(rename)
dnl checks for c library functions
AC_CHECK_FUNCS(bcopy bzero confstr fnmatch \
AC_CHECK_FUNCS(bcopy bzero confstr faccessat fnmatch \
getaddrinfo gethostbyname getservbyname getservent inet_aton \
memmove pathconf putenv raise regcomp regexec \
setenv setlinebuf setlocale setvbuf siginterrupt strchr \
@ -739,7 +739,8 @@ AC_CHECK_FUNCS(getpwent getpwnam getpwuid)
AC_REPLACE_FUNCS(getcwd memset)
AC_REPLACE_FUNCS(strcasecmp strcasestr strerror strftime strnlen strpbrk strstr)
AC_REPLACE_FUNCS(strtod strtol strtoul strtoll strtoull strtoimax strtoumax)
AC_REPLACE_FUNCS(fdprintf)
AC_REPLACE_FUNCS(dprintf)
AC_REPLACE_FUNCS(strchrnul)
AC_CHECK_DECLS([confstr])
AC_CHECK_DECLS([printf])
@ -904,6 +905,8 @@ BASH_CHECK_TYPE(socklen_t, [#include <sys/socket.h>], int, HAVE_SOCKLEN_T)
fi
BASH_TYPE_RLIMIT
AC_CHECK_SIZEOF(intmax_t, 8)
dnl presence and contents of structures used by system calls
BASH_STRUCT_TERMIOS_LDISC
BASH_STRUCT_TERMIO_LDISC
@ -917,6 +920,8 @@ AC_STRUCT_TM
AC_STRUCT_TIMEZONE
BASH_STRUCT_TIMEZONE
BASH_STRUCT_WEXITSTATUS_OFFSET
dnl presence and behavior of C library functions
BASH_FUNC_STRSIGNAL
BASH_FUNC_OPENDIR_CHECK

1145
configure.in.bash40 Normal file

File diff suppressed because it is too large Load Diff

1145
configure.in.orig Normal file

File diff suppressed because it is too large Load Diff

1145
configure.in.save Normal file

File diff suppressed because it is too large Load Diff

126
doc/FAQ
View File

@ -1,4 +1,4 @@
This is the Bash FAQ, version 4.11, for Bash version 4.1.
This is the Bash FAQ, version 4.12, for Bash version 4.2.
This document contains a set of frequently-asked questions concerning
Bash, the GNU Bourne-Again Shell. Bash is a freely-available command
@ -36,8 +36,8 @@ A10) What is the bash `posix mode'?
Section B: The latest version
B1) What's new in version 4.1?
B2) Are there any user-visible incompatibilities between bash-4.1 and
B1) What's new in version 4.2?
B2) Are there any user-visible incompatibilities between bash-4.2 and
previous bash versions?
Section C: Differences from other Unix shells
@ -144,26 +144,26 @@ of Case Western Reserve University.
A2) What's the latest version?
The latest version is 4.1, first made available on 31 December, 2009.
The latest version is 4.2, first made available on 14 February, 2011.
A3) Where can I get it?
Bash is the GNU project's shell, and so is available from the
master GNU archive site, ftp.gnu.org, and its mirrors. The
latest version is also available for FTP from ftp.cwru.edu.
The following URLs tell how to get version 4.1:
The following URLs tell how to get version 4.2:
ftp://ftp.gnu.org/pub/gnu/bash/bash-4.1.tar.gz
ftp://ftp.cwru.edu/pub/bash/bash-4.1.tar.gz
ftp://ftp.gnu.org/pub/gnu/bash/bash-4.2.tar.gz
ftp://ftp.cwru.edu/pub/bash/bash-4.2.tar.gz
Formatted versions of the documentation are available with the URLs:
ftp://ftp.gnu.org/pub/gnu/bash/bash-doc-4.1.tar.gz
ftp://ftp.cwru.edu/pub/bash/bash-doc-4.1.tar.gz
ftp://ftp.gnu.org/pub/gnu/bash/bash-doc-4.2.tar.gz
ftp://ftp.cwru.edu/pub/bash/bash-doc-4.2.tar.gz
Any patches for the current version are available with the URL:
ftp://ftp.cwru.edu/pub/bash/bash-4.1-patches/
ftp://ftp.cwru.edu/pub/bash/bash-4.2-patches/
A4) On what machines will bash run?
@ -219,7 +219,7 @@ Mark began to work with bash-2.05, but I don't know the current status.
Bash-3.0 compiles and runs with no modifications under Microsoft's Services
for Unix (SFU), once known as Interix. I do not anticipate any problems
with building bash-4.1, but will gladly accept any patches that are needed.
with building bash-4.2, but will gladly accept any patches that are needed.
A6) How can I build bash with gcc?
@ -388,14 +388,88 @@ They are also listed in a section in the Bash Reference Manual
Section B: The latest version
B1) What's new in version 4.1?
B1) What's new in version 4.2?
Bash-4.1 is the first revision to the fourth major release of bash.
Bash-4.2 is the second revision to the fourth major release of bash.
Bash-4.1 contains the following new features (see the manual page for
complete descriptions and the CHANGES and NEWS files in the bash-4.1
Bash-4.2 contains the following new features (see the manual page for
complete descriptions and the CHANGES and NEWS files in the bash-4.2
distribution):
o `exec -a foo' now sets $0 to `foo' in an executable shell script without a
leading #!.
o Subshells begun to execute command substitutions or run shell functions or
builtins in subshells do not reset trap strings until a new trap is
specified. This allows $(trap) to display the caller's traps and the
trap strings to persist until a new trap is set.
o `trap -p' will now show signals ignored at shell startup, though their
disposition still cannot be modified.
o $'...', echo, and printf understand \uXXXX and \UXXXXXXXX escape sequences.
o declare/typeset has a new `-g' option, which creates variables in the
global scope even when run in a shell function.
o test/[/[[ have a new -v variable unary operator, which returns success if
`variable' has been set.
o Posix parsing changes to allow `! time command' and multiple consecutive
instances of `!' (which toggle) and `time' (which have no cumulative
effect).
o Posix change to allow `time' as a command by itself to print the elapsed
user, system, and real times for the shell and its children.
o $((...)) is always parsed as an arithmetic expansion first, instead of as
a potential nested command substitution, as Posix requires.
o A new FUNCNEST variable to allow the user to control the maximum shell
function nesting (recursive execution) level.
o The mapfile builtin now supplies a third argument to the callback command:
the line about to be assigned to the supplied array index.
o The printf builtin has as new %(fmt)T specifier, which allows time values
to use strftime-like formatting.
o There is a new `compat41' shell option.
o The cd builtin has a new Posix-mandated `-e' option.
o Negative subscripts to indexed arrays, previously errors, now are treated
as offsets from the maximum assigned index + 1.
o Negative length specifications in the ${var:offset:length} expansion,
previously errors, are now treated as offsets from the end of the variable.
o Parsing change to allow `time -p --'.
o Posix-mode parsing change to not recognize `time' as a keyword if the
following token begins with a `-'. This means no more Posix-mode
`time -p'. Posix interpretation 267.
o There is a new `lastpipe' shell option that runs the last command of a
pipeline in the current shell context. The lastpipe option has no
effect if job control is enabled.
o History expansion no longer expands the `$!' variable expansion.
o Posix mode shells no longer exit if a variable assignment error occurs
with an assignment preceding a command that is not a special builtin.
o Non-interactive mode shells exit if -u is enabled an an attempt is made
to use an unset variable with the % or # expansions, the `//', `^', or
`,' expansions, or the parameter length expansion.
o Posix-mode shells use the argument passed to `.' as-is if a $PATH search
fails, effectively searching the current directory. Posix-2008 change.
A short feature history dating back to Bash-2.0:
Bash-4.1 contained the following new features:
o Here-documents within $(...) command substitutions may once more be
delimited by the closing right paren, instead of requiring a newline.
@ -502,8 +576,6 @@ o New bindable readline variable: enable-meta-key. Controls whether or not
readline sends the smm/rmm sequences if the terminal indicates it has a
meta key that enables eight-bit characters.
A short feature history dating from Bash-2.0:
Bash-4.0 contained the following new features:
o When using substring expansion on the positional parameters, a starting
@ -901,14 +973,14 @@ grammar tighter and smaller (66 reduce-reduce conflicts gone)
lots of code now smaller and faster
test suite greatly expanded
B2) Are there any user-visible incompatibilities between bash-4.1 and
B2) Are there any user-visible incompatibilities between bash-4.2 and
previous bash versions?
There are a few incompatibilities between version 4.1 and previous
There are a few incompatibilities between version 4.2 and previous
versions. They are detailed in the file COMPAT in the bash distribution.
That file is not meant to be all-encompassing; send mail to
bash-maintainers@gnu.org (or bug-bash@gnu.org if you would like
community discussion) if if you find something that's not mentioned there.
community discussion) if you find something that's not mentioned there.
Section C: Differences from other Unix shells
@ -1118,7 +1190,7 @@ C3) Which new features in ksh-93 are not in bash, and which are?
This list is current through ksh93t+ (05/05/2009)
New things in ksh-93 not in bash-4.1:
New things in ksh-93 not in bash-4.2:
floating point arithmetic and variables
math library functions
${!name[sub]} name of subscript for associative array
@ -1140,7 +1212,7 @@ New things in ksh-93 not in bash-4.1:
`fc' has been renamed to `hist'
`.' can execute shell functions
getopts -a
printf %B, %H, %P, %R, %T, %Z modifiers, output base for %d, `=' flag
printf %B, %H, %P, %R, %Z modifiers, output base for %d, `=' flag
read -n/-N differ/-v
set -o showme/-o multiline (bash default)
`sleep' and `getconf' builtins (bash has loadable versions)
@ -1148,16 +1220,14 @@ New things in ksh-93 not in bash-4.1:
[[ -R name ]] (checks whether or not name is a nameref)
typeset -C/-S/-T/-X/-h/-s
experimental `type' definitions (a la typedef) using typeset
negative subscripts for indexed array variables
array expansions ${array[sub1..sub2]} and ${!array[sub1..sub2]}
associative array assignments using `;' as element separator
command substitution $(n<#) expands to current byte offset for fd N
new '${ ' form of command substitution, executed in current shell
new >;/<>;/<#pat/<##pat/<#/># redirections
brace expansion printf-like formats
[[ -v var ]] operators (checks whether or not var is set)
New things in ksh-93 present in bash-4.1:
New things in ksh-93 present in bash-4.2:
associative arrays
[n]<&word- and [n]>&word- redirections (combination dup and close)
for (( expr1; expr2; expr3 )) ; do list; done - arithmetic for command
@ -1165,6 +1235,7 @@ New things in ksh-93 present in bash-4.1:
expansions: ${!param}, ${param:offset[:len]}, ${param/pat[/str]},
${!param*}
compound array assignment
negative subscripts for indexed array variables
the `!' reserved word
loadable builtins -- but ksh uses `builtin' while bash uses `enable'
new $'...' and $"..." quoting
@ -1174,6 +1245,7 @@ New things in ksh-93 present in bash-4.1:
`command', `builtin', `disown' builtins
echo -e
exec -c/-a
printf %T modifier
read -A (bash uses read -a)
read -t/-d
trap -p
@ -1193,6 +1265,7 @@ New things in ksh-93 present in bash-4.1:
negative offsets in ${param:offset:length}
redirection operators preceded with {varname} to store fd number in varname
DEBUG can force skipping following command
[[ -v var ]] operator (checks whether or not var is set)
Section D: Why does bash do some things differently than other Unix shells?
@ -1778,7 +1851,8 @@ compat40 set
- the < and > operators to the [[ command do not consider the current
locale when comparing strings
- interrupting a command list such as "a ; b ; c" causes the execution
of the entire list to be aborted
of the entire list to be aborted (in versions before bash-4.0,
interrupting one command in a list caused the next to be executed)
Section F: Things to watch out for on certain Unix versions

View File

@ -161,7 +161,7 @@ html: ${HTMLFILES}
pdf: ${PDFFILES}
bashref.dvi: $(BASHREF_FILES) $(HSUSER) $(RLUSER)
${SET_TEXINPUTS} $(TEXI2DVI) $(srcdir)/bashref.texi
${SET_TEXINPUTS} $(TEXI2DVI) $(srcdir)/bashref.texi || { ${RM} $@ ; exit 1; }
bashref.info: $(BASHREF_FILES) $(HSUSER) $(RLUSER)
$(MAKEINFO) --no-split -I$(TEXINPUTDIR) $(srcdir)/bashref.texi

2338
doc/bash.0

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

Binary file not shown.

13156
doc/bash.ps

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@ -16,7 +16,7 @@ This is Edition @value{EDITION}, last updated @value{UPDATED},
of @cite{The GNU Bash Reference Manual},
for @code{Bash}, Version @value{VERSION}.
Copyright @copyright{} 1988--2009 Free Software Foundation, Inc.
Copyright @copyright{} 1988--2011 Free Software Foundation, Inc.
Permission is granted to make and distribute verbatim copies of
this manual provided the copyright notice and this permission notice
@ -522,6 +522,12 @@ the eight-bit character whose value is the octal value @var{nnn}
@item \x@var{HH}
the eight-bit character whose value is the hexadecimal value @var{HH}
(one or two hex digits)
@item \u@var{HHHH}
the Unicode (ISO/IEC 10646) character whose value is the hexadecimal value
@var{HHHH} (one to four hex digits)
@item \U@var{HHHHHHHH}
the Unicode (ISO/IEC 10646) character whose value is the hexadecimal value
@var{HHHHHHHH} (one to eight hex digits)
@item \c@var{x}
a control-@var{x} character
@end table
@ -590,6 +596,7 @@ some other grouping.
* Lists:: How to execute commands sequentially.
* Compound Commands:: Shell commands for control flow.
* Coprocesses:: Two-way communication between commands.
* GNU Parallel:: Running commands in parallel.
@end menu
@node Simple Commands
@ -641,6 +648,9 @@ The statistics currently consist of elapsed (wall-clock) time and
user and system time consumed by the command's execution.
The @option{-p} option changes the output format to that specified
by @sc{posix}.
When the shell is in @sc{posix} mode (@pxref{Bash POSIX Mode}),
it does not recognize @code{time} as a reserved word if the next
token begins with a @samp{-}.
The @env{TIMEFORMAT} variable may be set to a format string that
specifies how the timing information should be displayed.
@xref{Bash Variables}, for a description of the available formats.
@ -648,6 +658,12 @@ The use of @code{time} as a reserved word permits the timing of
shell builtins, shell functions, and pipelines. An external
@code{time} command cannot time these easily.
When the shell is in @sc{posix} mode (@pxref{Bash POSIX Mode}), @code{time}
may be followed by a newline. In this case, the shell displays the
total user and system time consumed by the shell and its children.
The @env{TIMEFORMAT} variable may be used to specify the format of
the time information.
If the pipeline is not executed asynchronously (@pxref{Lists}), the
shell waits for all commands in the pipeline to complete.
@ -804,7 +820,7 @@ until it evaluates to zero.
Each time @var{expr2} evaluates to a non-zero value, @var{commands} are
executed and the arithmetic expression @var{expr3} is evaluated.
If any expression is omitted, it behaves as if it evaluates to 1.
The return value is the exit status of the last command in @var{list}
The return value is the exit status of the last command in @var{commands}
that is executed, or false if any of the expressions is invalid.
@end table
@ -979,7 +995,7 @@ substitution, and quote removal are performed.
Conditional operators such as @samp{-f} must be unquoted to be recognized
as primaries.
When used with @samp{[[}, The @samp{<} and @samp{>} operators sort
When used with @samp{[[}, the @samp{<} and @samp{>} operators sort
lexicographically using the current locale.
When the @samp{==} and @samp{!=} operators are used, the string to the
@ -1119,13 +1135,88 @@ command (@pxref{Redirections}).
The file descriptors can be utilized as arguments to shell commands
and redirections using standard word expansions.
The process id of the shell spawned to execute the coprocess is
The process ID of the shell spawned to execute the coprocess is
available as the value of the variable @var{NAME}_PID.
The @code{wait}
builtin command may be used to wait for the coprocess to terminate.
The return status of a coprocess is the exit status of @var{command}.
@node GNU Parallel
@subsection GNU Parallel
GNU Parallel, as its name suggests, can be used to build and run commands
in parallel. You may run the same command with different arguments, whether
they are filenames, usernames, hostnames, or lines read from files.
For a complete description, refer to the GNU Parallel documentation. A few
examples should provide a brief introduction to its use.
For example, it is easy to prefix each line in a text file with a specified
string:
@example
cat file | parallel -k echo prefix_string
@end example
@noindent
The @option{-k} option is required to preserve the lines' order.
Similarly, you can append a specified string to each line in a text file:
@example
cat file | parallel -k echo @{@} append_string
@end example
You can use Parallel to move files from the current directory when the
number of files is too large to process with one @code{mv} invocation:
@example
ls | parallel mv @{@} destdir
@end example
As you can see, the @{@} is replaced with each line read from standard input.
This will run as many @code{mv} commands as there are files in the current
directory. You can emulate a parallel @code{xargs} by adding the @option{-X}
option:
@example
ls | parallel -X mv @{@} destdir
@end example
GNU Parallel can replace certain common idioms that operate on lines read
from a file (in this case, filenames):
@example
for x in $(cat list); do
do-something1 $x config-$x
do-something2 < $x
done | process-output
@end example
@noindent
with a more compact syntax reminiscent of lambdas:
@example
cat list | parallel "do-something1 @{@} config-@{@} ; do-something2 < @{@}" | process-output
@end example
Parallel provides a built-in mechanism to remove filename extensions, which
lends itself to batch file transformations or renaming:
@example
ls *.gz | parallel -j+0 "zcat @{@} | bzip2 >@{.@}.bz2 && rm @{@}"
@end example
@noindent
This will recompress all files in the current directory with names ending
in .gz using bzip2, running one job per CPU (-j+0) in parallel.
If a command generates output, you may want to preserve the input order in
the output. For instance, the following command
@example
@{ echo foss.org.my ; echo debian.org; echo freenetproject.org; @} | parallel traceroute
@end example
@noindent
will display as output the traceroute invocation that finishes first. Using
the @option{-k} option, as we saw above
@example
@{ echo foss.org.my ; echo debian.org; echo freenetproject.org; @} | parallel -k traceroute
@end example
@noindent
will ensure that the output of @code{traceroute foss.org.my} is displayed first.
@node Shell Functions
@section Shell Functions
@cindex shell function
@ -1142,7 +1233,8 @@ shell context; no new process is created to interpret them.
Functions are declared using this syntax:
@rwindex function
@example
[ @code{function} ] @var{name} () @var{compound-command} [ @var{redirections} ]
@var{name} () @var{compound-command} [ @var{redirections} ]@*or@*
@code{function} @var{name} [()] @var{compound-command} [ @var{redirections} ]
@end example
This defines a shell function named @var{name}. The reserved
@ -1198,6 +1290,11 @@ shell option has been enabled.
@xref{Bourne Shell Builtins}, for the description of the
@code{trap} builtin.
The @env{FUNCNEST} variable, if set to a numeric value greater
than 0, defines a maximum function nesting level. Function
invocations that exceed the limit cause the entire command to
abort.
If the builtin command @code{return}
is executed in a function, the function completes and
execution resumes with the next command after the function
@ -1232,8 +1329,10 @@ in multiple identically-named entries in the environment passed to the
shell's children.
Care should be taken in cases where this may cause a problem.
Functions may be recursive. No limit is placed on the number of
recursive calls.
Functions may be recursive.
The @code{FUNCNEST} variable may be used to limit the depth of the
function call stack and restrict the number of function invocations.
By default, no limit is placed on the number of recursive calls.
@node Shell Parameters
@section Shell Parameters
@ -1283,7 +1382,7 @@ In the context where an assignment statement is assigning a value
to a shell variable or array index (@pxref{Arrays}), the @samp{+=}
operator can be used to
append to or add to the variable's previous value.
When @samp{+=} is applied to a variable for which the integer attribute
When @samp{+=} is applied to a variable for which the @var{integer} attribute
has been set, @var{value} is evaluated as an arithmetic expression and
added to the variable's current value, which is also evaluated.
When @samp{+=} is applied to an array variable using compound assignment
@ -1618,7 +1717,7 @@ Bash uses the value of the variable formed from the rest of
expanded and that value is used in the rest of the substitution, rather
than the value of @var{parameter} itself.
This is known as @code{indirect expansion}.
The exceptions to this are the expansions of $@{!@var{prefix*}@}
The exceptions to this are the expansions of $@{!@var{prefix}@*@}
and $@{!@var{name}[@@]@}
described below.
The exclamation point must immediately follow the left brace in order to
@ -1672,9 +1771,13 @@ If @var{length} is omitted, expands to the substring of
(@pxref{Shell Arithmetic}).
This is referred to as Substring Expansion.
@var{length} must evaluate to a number greater than or equal to zero.
If @var{offset} evaluates to a number less than zero, the value
is used as an offset from the end of the value of @var{parameter}.
If @var{length} evaluates to a number less than zero, and @var{parameter}
is not @samp{@@} and not an indexed or associative array, it is interpreted
as an offset from the end of the value of @var{parameter} rather than
a number of characters, and the expansion is the characters between the
two offsets.
If @var{parameter} is @samp{@@}, the result is @var{length} positional
parameters beginning at @var{offset}.
If @var{parameter} is an indexed array name subscripted
@ -2838,7 +2941,7 @@ The return status is zero unless @var{n} is not greater than or equal to 1.
@item cd
@btindex cd
@example
cd [-L|-P] [@var{directory}]
cd [-L|[-P [-e]]] [@var{directory}]
@end example
Change the current working directory to @var{directory}.
If @var{directory} is not given, the value of the @env{HOME} shell
@ -2848,6 +2951,10 @@ If @var{directory} begins with a slash, @env{CDPATH} is not used.
The @option{-P} option means to not follow symbolic links; symbolic
links are followed by default or with the @option{-L} option.
If the @option{-e} option is supplied with @option{-P}
and the current working directory cannot be successfully determined
after a successful directory change, @code{cd} will return an unsuccessful
status.
If @var{directory} is @samp{-}, it is equivalent to @env{$OLDPWD}.
If a non-empty directory name from @env{CDPATH} is used, or if
@ -2954,7 +3061,7 @@ invocation if a new set of parameters is to be used.
When the end of options is encountered, @code{getopts} exits with a
return value greater than zero.
@env{OPTIND} is set to the index of the first non-option argument,
and @code{name} is set to @samp{?}.
and @var{name} is set to @samp{?}.
@code{getopts}
normally parses the positional parameters, but if more arguments are
@ -2986,10 +3093,12 @@ If @code{getopts} is silent, then a colon (@samp{:}) is placed in
@example
hash [-r] [-p @var{filename}] [-dt] [@var{name}]
@end example
Remember the full pathnames of commands specified as @var{name} arguments,
Each time @code{hash} is invoked, it remembers the full pathnames of the
commands specified as @var{name} arguments,
so they need not be searched for on subsequent invocations.
The commands are found by searching through the directories listed in
@env{$PATH}.
Any previously-remembered pathname is discarded.
The @option{-p} option inhibits the path search, and @var{filename} is
used as the location of @var{name}.
The @option{-r} option causes the shell to forget all remembered locations.
@ -3023,7 +3132,7 @@ is supplied.
@item readonly
@btindex readonly
@example
readonly [-aApf] [@var{name}[=@var{value}]] @dots{}
readonly [-aAf] [-p] [@var{name}[=@var{value}]] @dots{}
@end example
Mark each @var{name} as readonly.
The values of these names may not be changed by subsequent assignment.
@ -3032,8 +3141,11 @@ function.
The @option{-a} option means each @var{name} refers to an indexed
array variable; the @option{-A} option means each @var{name} refers
to an associative array variable.
If both options are supplied, @option{-A} takes precedence.
If no @var{name} arguments are given, or if the @option{-p}
option is supplied, a list of all readonly names is printed.
The other options may be used to restrict the output to a subset of
the set of readonly names.
The @option{-p} option causes output to be displayed in a format that
may be reused as input.
If a variable name is followed by =@var{value}, the value of
@ -3093,6 +3205,7 @@ be a @code{]}.
Expressions may be combined using the following operators, listed in
decreasing order of precedence.
The evaluation depends on the number of arguments; see below.
Operator precedence is used when there are five or more arguments.
@table @code
@item ! @var{expr}
@ -3129,6 +3242,7 @@ If the first argument is not a valid unary operator, the expression is
false.
@item 3 arguments
The following conditions are applied in the order listed.
If the second argument is one of the binary conditional
operators (@pxref{Bash Conditional Expressions}), the
result of the expression is the result of the binary test using the
@ -3153,6 +3267,9 @@ The expression is parsed and evaluated according to precedence
using the rules listed above.
@end table
When used with @code{test} or @samp{[}, the @samp{<} and @samp{>}
operators sort lexicographically using ASCII ordering.
@item times
@btindex times
@example
@ -3448,6 +3565,11 @@ If the @code{extdebug} shell option is enabled using @code{shopt}
(@pxref{The Shopt Builtin}), the source file name and line number where
the function is defined are displayed as well.
@option{-F} implies @option{-f}.
The @option{-g} option forces variables to be created or modified at
the global scope, even when @code{declare} is executed in a shell function.
It is ignored in all other cases.
The following options can be used to restrict output to variables with
the specified attributes or to give variables attributes:
@ -3496,8 +3618,9 @@ with the exceptions that @samp{+a}
may not be used to destroy an array variable and @samp{+r} will not
remove the readonly attribute.
When used in a function, @code{declare} makes each @var{name} local,
as with the @code{local} command. If a variable name is followed by
=@var{value}, the value of the variable is set to @var{value}.
as with the @code{local} command, unless the @samp{-g} option is used.
If a variable name is followed by =@var{value}, the value of the variable
is set to @var{value}.
The return status is zero unless an invalid option is encountered,
an attempt is made to define a function using @samp{-f foo=bar},
@ -3536,6 +3659,7 @@ backspace
@item \c
suppress further output
@item \e
@itemx \E
escape
@item \f
form feed
@ -3555,6 +3679,12 @@ the eight-bit character whose value is the octal value @var{nnn}
@item \x@var{HH}
the eight-bit character whose value is the hexadecimal value @var{HH}
(one or two hex digits)
@item \u@var{HHHH}
the Unicode (ISO/IEC 10646) character whose value is the hexadecimal value
@var{HHHH} (one to four hex digits)
@item \U@var{HHHHHHHH}
the Unicode (ISO/IEC 10646) character whose value is the hexadecimal value
@var{HHHHHHHH} (one to eight hex digits)
@end table
@item enable
@ -3679,7 +3809,8 @@ Specify the number of lines read between each call to @var{callback}.
If @option{-C} is specified without @option{-c},
the default quantum is 5000.
When @var{callback} is evaluated, it is supplied the index of the next
array element to be assigned as an additional argument.
array element to be assigned and the line to be assigned to that element
as additional arguments.
@var{callback} is evaluated after the line is read but before the
array element is assigned.
@ -3697,22 +3828,40 @@ printf [-v @var{var}] @var{format} [@var{arguments}]
@end example
Write the formatted @var{arguments} to the standard output under the
control of the @var{format}.
The @option{-v} option causes the output to be assigned to the variable
@var{var} rather than being printed to the standard output.
The @var{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
@var{argument}.
In addition to the standard @code{printf(1)} formats, @samp{%b} causes
@code{printf} to expand backslash escape sequences in the corresponding
@var{argument},
In addition to the standard @code{printf(1)} formats, @code{printf}
interprets the following extensions:
@table @code
@item %b
causes @code{printf} to expand backslash escape sequences in the
corresponding @var{argument},
(except that @samp{\c} terminates output, backslashes in
@samp{\'}, @samp{\"}, and @samp{\?} are not removed, and octal escapes
beginning with @samp{\0} may contain up to four digits),
and @samp{%q} causes @code{printf} to output the
beginning with @samp{\0} may contain up to four digits).
@item %q
causes @code{printf} to output the
corresponding @var{argument} in a format that can be reused as shell input.
@item %(@var{datefmt})T
causes @code{printf} to output the date-time string resulting from using
@var{datefmt} as a format string for @code{strftime}(3). The corresponding
@var{argument} is an integer representing the number of seconds since the
epoch. Two special argument values may be used: -1 represents the current
time, and -2 represents the time the shell was invoked.
@end table
The @option{-v} option causes the output to be assigned to the variable
@var{var} rather than being printed to the standard output.
@noindent
Arguments to non-string format specifiers are treated as C language constants,
except that a leading plus or minus sign is allowed, and if the leading
character is a single or double quote, the value is the ASCII value of
the following character.
The @var{format} is reused as necessary to consume all of the @var{arguments}.
If the @var{format} requires more @var{arguments} than are supplied, the
@ -3939,7 +4088,8 @@ The maximum amount of cpu time in seconds.
The maximum number of processes available to a single user.
@item -v
The maximum amount of virtual memory available to the process.
The maximum amount of virtual memory available to the shell, and, on
some systems, to its children.
@item -x
The maximum number of file locks.
@ -3999,8 +4149,8 @@ parameters, or to display the names and values of shell variables.
@item set
@btindex set
@example
set [--abefhkmnptuvxBCEHPT] [-o @var{option}] [@var{argument} @dots{}]
set [+abefhkmnptuvxBCEHPT] [+o @var{option}] [@var{argument} @dots{}]
set [--abefhkmnptuvxBCEHPT] [-o @var{option-name}] [@var{argument} @dots{}]
set [+abefhkmnptuvxBCEHPT] [+o @var{option-name}] [@var{argument} @dots{}]
@end example
If no options or arguments are supplied, @code{set} displays the names
@ -4361,7 +4511,29 @@ easy re-editing of multi-line commands.
@item compat31
If set, Bash
changes its behavior to that of version 3.1 with respect to quoted
arguments to the conditional command's =~ operator.
arguments to the conditional command's @samp{=~} operator.
@item compat32
If set, Bash
changes its behavior to that of version 3.2 with respect to locale-specific
string comparison when using the @samp{[[}
conditional command's @samp{<} and @samp{>} operators.
Bash versions prior to bash-4.0 use ASCII collation and strcmp(3);
bash-4.1 and later use the current locale's collation sequence and strcoll(3).
@item compat40
If set, Bash
changes its behavior to that of version 4.0 with respect to locale-specific
string comparison when using the @samp{[[}
conditional command's @samp{<} and @samp{>} operators (see previous item)
and the effect of interrupting a command list.
@item compat41
If set, Bash, when in posix mode, treats a single quote in a double-quoted
parameter expansion as a special character. The single quotes must match
(an even number) and the characters between the single quotes are considered
quoted. This is the behavior of @sc{posix} mode through version 4.1.
The default Bash behavior remains as in previous versions.
@item dirspell
If set, Bash
@ -4414,7 +4586,7 @@ subshells invoked with @code{( @var{command} )} inherit the
@item
Error tracing is enabled: command substitution, shell functions, and
subshells invoked with @code{( @var{command} )} inherit the
@code{ERROR} trap.
@code{ERR} trap.
@end enumerate
@item extglob
@ -4439,7 +4611,7 @@ This option is enabled by default.
@item globstar
If set, the pattern @samp{**} used in a filename expansion context will
match a files and zero or more directories and subdirectories.
match all files and zero or more directories and subdirectories.
If the pattern is followed by a @samp{/}, only directories and
subdirectories match.
@ -4479,6 +4651,10 @@ to cause that word and all remaining characters on that
line to be ignored in an interactive shell.
This option is enabled by default.
@item lastpipe
If set, and job control is not active, the shell runs the last command of
a pipeline not executed in the background in the current shell environment.
@item lithist
If enabled, and the @code{cmdhist}
option is enabled, multi-line commands are saved to the history with
@ -4621,9 +4797,10 @@ A list of characters that separate fields; used when the shell splits
words as part of expansion.
@item MAIL
If this parameter is set to a filename and the @env{MAILPATH} variable
If this parameter is set to a filename or directory name
and the @env{MAILPATH} variable
is not set, Bash informs the user of the arrival of mail in
the specified file.
the specified file or Maildir-format directory.
@item MAILPATH
A colon-separated list of filenames which the shell periodically checks
@ -4685,13 +4862,13 @@ starts up, each shell option in the list will be enabled before
reading any startup files. This variable is readonly.
@item BASHPID
Expands to the process id of the current Bash process.
Expands to the process ID of the current Bash process.
This differs from @code{$$} under certain circumstances, such as subshells
that do not require Bash to be re-initialized.
@item BASH_ALIASES
An associative array variable whose members correspond to the internal
list of aliases as maintained by the @code{alias} builtin
list of aliases as maintained by the @code{alias} builtin.
(@pxref{Bourne Shell Builtins}).
Elements added to this array appear in the alias list; unsetting array
elements cause aliases to be removed from the alias list.
@ -4741,11 +4918,11 @@ The command argument to the @option{-c} invocation option.
@item BASH_LINENO
An array variable whose members are the line numbers in source files
corresponding to each member of @var{FUNCNAME}.
@code{$@{BASH_LINENO[$i]@}} is the line number in the source file where
where each corresponding member of @var{FUNCNAME} was invoked.
@code{$@{BASH_LINENO[$i]@}} is the line number in the source file
(@code{$@{BASH_SOURCE[$i+1]@}}) where
@code{$@{FUNCNAME[$i]@}} was called (or @code{$@{BASH_LINENO[$i-1]@}} if
referenced within another shell function).
The corresponding source file name is @code{$@{BASH_SOURCE[$i]@}}.
referenced within another shell function).
Use @code{LINENO} to obtain the current line number.
@item BASH_REMATCH
@ -4759,8 +4936,11 @@ string matching the @var{n}th parenthesized subexpression.
This variable is read-only.
@item BASH_SOURCE
An array variable whose members are the source filenames corresponding
to the elements in the @code{FUNCNAME} array variable.
An array variable whose members are the source filenames where the
corresponding shell function names in the @code{FUNCNAME} array
variable are defined.
The shell function @code{$@{FUNCNAME[$i]@}} is defined in the file
@code{$@{BASH_SOURCE[$i]@}} and called from @code{$@{BASH_SOURCE[$i+1]@}}
@item BASH_SUBSHELL
Incremented by one each time a subshell or subshell environment is spawned.
@ -4811,7 +4991,7 @@ descriptor) and then unsetting it will result in the standard error
being closed.
@item COLUMNS
Used by the @code{select} builtin command to determine the terminal width
Used by the @code{select} command to determine the terminal width
when printing selection lists. Automatically set upon receipt of a
@code{SIGWINCH}.
@ -4872,6 +5052,10 @@ An array variable from which Bash reads the possible completions
generated by a shell function invoked by the programmable completion
facility (@pxref{Programmable Completion}).
@item COPROC
An array variable created to hold the file descriptors
for output from and input to an unnamed coprocess (@pxref{Coprocesses}).
@item DIRSTACK
An array variable containing the current contents of the directory stack.
Directories appear in the stack in the order they are displayed by the
@ -4886,7 +5070,11 @@ it is subsequently reset.
@item EMACS
If Bash finds this variable in the environment when the shell
starts with value @samp{t}, it assumes that the shell is running in an
emacs shell buffer and disables line editing.
Emacs shell buffer and disables line editing.
@item ENV
Similar to @code{BASH_ENV}; used when the shell is invoked in
@sc{posix} Mode (@pxref{Bash POSIX Mode}).
@item EUID
The numeric effective user id of the current user. This variable
@ -4909,12 +5097,26 @@ An array variable containing the names of all shell functions
currently in the execution call stack.
The element with index 0 is the name of any currently-executing
shell function.
The bottom-most element is @code{"main"}.
The bottom-most element (the one with the highest index)
is @code{"main"}.
This variable exists only when a shell function is executing.
Assignments to @env{FUNCNAME} have no effect and return an error status.
If @env{FUNCNAME} is unset, it loses its special properties, even if
it is subsequently reset.
This variable can be used with @code{BASH_LINENO} and @code{BASH_SOURCE}.
Each element of @code{FUNCNAME} has corresponding elements in
@code{BASH_LINENO} and @code{BASH_SOURCE} to describe the call stack.
For instance, @code{$@{FUNCNAME[$i]@}} was called from the file
@code{$@{BASH_SOURCE[$i+1]@}} at line number @code{$@{BASH_LINENO[$i]@}}.
The @code{caller} builtin displays the current call stack using this
information.
@item FUNCNEST
If set to a numeric value greater than 0, defines a maximum function
nesting level. Function invocations that exceed this nesting level
will cause the current command to abort.
@item GLOBIGNORE
A colon-separated list of patterns defining the set of filenames to
be ignored by filename expansion.
@ -5078,7 +5280,7 @@ This variable determines the locale category used for number formatting.
The line number in the script or shell function currently executing.
@item LINES
Used by the @code{select} builtin command to determine the column length
Used by the @code{select} command to determine the column length
for printing selection lists. Automatically set upon receipt of a
@code{SIGWINCH}.
@ -5094,6 +5296,10 @@ for mail, the shell does so before displaying the primary prompt.
If this variable is unset, or set to a value that is not a number
greater than or equal to zero, the shell disables mail checking.
@item MAPFILE
An array variable created to hold the text read by the
@code{mapfile} builtin when no variable name is supplied.
@item OLDPWD
The previous working directory as set by the @code{cd} builtin.
@ -5156,6 +5362,14 @@ Each time this parameter is referenced, a random integer
between 0 and 32767 is generated. Assigning a value to this
variable seeds the random number generator.
@item READLINE_LINE
The contents of the Readline line buffer, for use
with @samp{bind -x} (@pxref{Bash Builtins}).
@item READLINE_POINT
The position of the insertion point in the Readline line buffer, for use
with @samp{bind -x} (@pxref{Bash Builtins}).
@item REPLY
The default variable for the @code{read} builtin.
@ -5284,8 +5498,9 @@ bash [long-opt] [-abefhkmnptuvxdBCDHP] [-o @var{option}] [-O @var{shopt_option}]
bash [long-opt] -s [-abefhkmnptuvxdBCDHP] [-o @var{option}] [-O @var{shopt_option}] [@var{argument} @dots{}]
@end example
In addition to the single-character shell command-line options
(@pxref{The Set Builtin}), there are several multi-character
All of the single-character options used with the @code{set} builtin
(@pxref{The Set Builtin}) can be used as options when the shell is invoked.
In addition, there are several multi-character
options that you can use. These options must appear on the command
line before the single-character options to be recognized.
@ -5294,9 +5509,7 @@ line before the single-character options to be recognized.
Arrange for the debugger profile to be executed before the shell
starts. Turns on extended debugging mode (see @ref{The Shopt Builtin}
for a description of the @code{extdebug} option to the @code{shopt}
builtin) and shell function tracing
(see @ref{The Set Builtin} for a description of the @code{-o functrace}
option).
builtin).
@item --dump-po-strings
A list of all double-quoted strings preceded by @samp{$}
@ -5527,7 +5740,7 @@ No other startup files are read.
@subsubheading Invoked by remote shell daemon
Bash attempts to determine when it is being run with its standard input
connected to a a network connection, as if by the remote shell
connected to a network connection, as when executed by the remote shell
daemon, usually @code{rshd}, or the secure shell daemon @code{sshd}.
If Bash determines it is being run in
this fashion, it reads and executes commands from @file{~/.bashrc}, if that
@ -5722,8 +5935,9 @@ If the @var{file} argument to one of the primaries is one of
@file{/dev/stdin}, @file{/dev/stdout}, or @file{/dev/stderr}, file
descriptor 0, 1, or 2, respectively, is checked.
When used with @samp{[[}, The @samp{<} and @samp{>} operators sort
When used with @samp{[[}, the @samp{<} and @samp{>} operators sort
lexicographically using the current locale.
The @code{test} command uses ASCII ordering.
Unless otherwise specified, primaries that operate on files follow symbolic
links and operate on the target of the link, rather than the link itself.
@ -5777,20 +5991,24 @@ True if @var{file} exists and is writable.
@item -x @var{file}
True if @var{file} exists and is executable.
@item -O @var{file}
True if @var{file} exists and is owned by the effective user id.
@item -G @var{file}
True if @var{file} exists and is owned by the effective group id.
@item -L @var{file}
True if @var{file} exists and is a symbolic link.
@item -N @var{file}
True if @var{file} exists and has been modified since it was last read.
@item -O @var{file}
True if @var{file} exists and is owned by the effective user id.
@item -S @var{file}
True if @var{file} exists and is a socket.
@item -N @var{file}
True if @var{file} exists and has been modified since it was last read.
@item @var{file1} -ef @var{file2}
True if @var{file1} and @var{file2} refer to the same device and
inode numbers.
@item @var{file1} -nt @var{file2}
True if @var{file1} is newer (according to modification date)
@ -5800,15 +6018,14 @@ than @var{file2}, or if @var{file1} exists and @var{file2} does not.
True if @var{file1} is older than @var{file2},
or if @var{file2} exists and @var{file1} does not.
@item @var{file1} -ef @var{file2}
True if @var{file1} and @var{file2} refer to the same device and
inode numbers.
@item -o @var{optname}
True if shell option @var{optname} is enabled.
True if the shell option @var{optname} is enabled.
The list of options appears in the description of the @option{-o}
option to the @code{set} builtin (@pxref{The Set Builtin}).
@item -v @var{varname}
True if the shell variable @var{varname} is set (has been assigned a value).
@item -z @var{string}
True if the length of @var{string} is zero.
@ -5928,12 +6145,12 @@ The value of a variable is evaluated as an arithmetic expression
when it is referenced, or when a variable which has been given the
@var{integer} attribute using @samp{declare -i} is assigned a value.
A null value evaluates to 0.
A shell variable need not have its integer attribute turned on
A shell variable need not have its @var{integer} attribute turned on
to be used in an expression.
Constants with a leading 0 are interpreted as octal numbers.
A leading @samp{0x} or @samp{0X} denotes hexadecimal. Otherwise,
numbers take the form [@var{base}@code{#}]@var{n}, where @var{base}
numbers take the form [@var{base}@code{#}]@var{n}, where the optional @var{base}
is a decimal number between 2 and 64 representing the arithmetic
base, and @var{n} is a number in that base. If @var{base}@code{#} is
omitted, then base 10 is used.
@ -6028,8 +6245,11 @@ name[@var{subscript}]=@var{value}
@noindent
The @var{subscript}
is treated as an arithmetic expression that must evaluate to a number
greater than or equal to zero. To explicitly declare an array, use
is treated as an arithmetic expression that must evaluate to a number.
If @var{subscript} evaluates to a number less than zero, it is used as
an offset from one greater than the array's maximum index (so a subcript
of -1 refers to the last element of the array).
To explicitly declare an array, use
@example
declare -a @var{name}
@end example
@ -6111,6 +6331,7 @@ entire array.
The @code{declare}, @code{local}, and @code{readonly}
builtins each accept a @option{-a} option to specify an indexed
array and a @option{-A} option to specify an associative array.
If both options are supplied, @option{-A} takes precedence.
The @code{read} builtin accepts a @option{-a}
option to assign a list of words read from the standard input
to an array, and can read values from the standard input into
@ -6439,6 +6660,11 @@ is not found.
Non-interactive shells exit if a syntax error in an arithmetic expansion
results in an invalid expression.
@item
Non-interactive shells exit if there is a syntax error in a script read
with the @code{.} or @code{source} builtins, or in a string processed by
the @code{eval} builtin.
@item
Redirection operators do not perform filename expansion on the word
in the redirection unless the shell is interactive.
@ -6458,19 +6684,28 @@ causes a fatal syntax error in non-interactive shells.
during command lookup.
@item
If a @sc{posix} special builtin returns an error status, a
non-interactive shell exits. The fatal errors are those listed in
the POSIX standard, and include things like passing incorrect options,
redirection errors, variable assignment errors for assignments preceding
the command name, and so on.
The @code{time} reserved word may be used by itself as a command. When
used in this way, it displays timing statistics for the shell and its
completed children. The @env{TIMEFORMAT} variable controls the format
of the timing information.
@item
If @env{CDPATH} is set, the @code{cd} builtin will not implicitly
append the current directory to it. This means that @code{cd} will
fail if no valid directory name can be constructed from
any of the entries in @env{$CDPATH}, even if the a directory with
the same name as the name given as an argument to @code{cd} exists
in the current directory.
When parsing and expanding a $@{@dots{}@} expansion that appears within
double quotes, single quotes are no longer special and cannot be used to
quote a closing brace or other special character, unless the operator is
one of those defined to perform pattern removal. In this case, they do
not have to appear as matched pairs.
@item
The parser does not recognize @code{time} as a reserved word if the next
token begins with a @samp{-}.
@item
If a @sc{posix} special builtin returns an error status, a
non-interactive shell exits. The fatal errors are those listed in
the @sc{posix} standard, and include things like passing incorrect options,
redirection errors, variable assignment errors for assignments preceding
the command name, and so on.
@item
A non-interactive shell exits with an error status if a variable
@ -6479,6 +6714,11 @@ statements.
A variable assignment error occurs, for example, when trying to assign
a value to a readonly variable.
@item
A non-interactive shell exists with an error status if a variable
assignment error occurs in an assignment statement preceding a special
builtin, but not with any other simple command.
@item
A non-interactive shell exits with an error status if the iteration
variable in a @code{for} statement or the selection variable in a
@ -6544,10 +6784,6 @@ constructed from @code{$PWD} and the directory name supplied as an argument
does not refer to an existing directory, @code{cd} will fail instead of
falling back to @var{physical} mode.
@item
When the @code{pwd} builtin is supplied the @option{-P} option, it resets
@code{$PWD} to a pathname containing no symlinks.
@item
The @code{pwd} builtin verifies that the value it prints is the same as the
current directory, even if it is not asked to check the file system with the
@ -7269,7 +7505,7 @@ Include support for the @code{[[} conditional command.
(@pxref{Conditional Constructs}).
@item --enable-cond-regexp
Include support for matching POSIX regular expressions using the
Include support for matching @sc{posix} regular expressions using the
@samp{=~} binary operator in the @code{[[} conditional command.
(@pxref{Conditional Constructs}).
@ -7350,8 +7586,8 @@ when called as @code{rbash}, enters a restricted mode. See
@ref{The Restricted Shell}, for a description of restricted mode.
@item --enable-select
Include the @code{select} builtin, which allows the generation of simple
menus (@pxref{Conditional Constructs}).
Include the @code{select} compound command, which allows the generation of
simple menus (@pxref{Conditional Constructs}).
@item --enable-separate-helpfiles
Use external files for the documentation displayed by the @code{help} builtin

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -21,7 +21,7 @@ RREESSTTRRIICCTTEEDD SSHHEELLLL
+o specifying a file name containing a // as an argument to the ..
builtin command
+o Specifying a filename containing a slash as an argument to the
+o specifying a filename containing a slash as an argument to the
--pp option to the hhaasshh builtin command
+o importing function definitions from the shell environment at
@ -39,7 +39,7 @@ RREESSTTRRIICCTTEEDD SSHHEELLLL
+o adding or deleting builtin commands with the --ff and --dd options
to the eennaabbllee builtin command
+o Using the eennaabbllee builtin command to enable disabled shell
+o using the eennaabbllee builtin command to enable disabled shell
builtins
+o specifying the --pp option to the ccoommmmaanndd builtin command

View File

@ -1,6 +1,6 @@
%!PS-Adobe-3.0
%%Creator: groff version 1.19.2
%%CreationDate: Wed Dec 30 13:07:37 2009
%%CreationDate: Tue Dec 28 14:30:24 2010
%%DocumentNeededResources: font Times-Roman
%%+ font Times-Bold
%%DocumentSuppliedResources: procset grops 1.19 2
@ -247,10 +247,10 @@ G(TH)-.189 E F4(,)A F3(ENV)2.25 E F4(,)A F0(or)2.25 E F3 -.27(BA)2.5 G
(pecifying command names containing)-32.5 E F2(/)2.5 E F0 32.5<8373>108
216 S(pecifying a \214le name containing a)-32.5 E F2(/)2.5 E F0
(as an ar)2.5 E(gument to the)-.18 E F2(.)2.5 E F0 -.2(bu)5 G
(iltin command).2 E 32.5<8353>108 232.8 S .351
(pecifying a \214lename containing a slash as an ar)-32.5 F .351
(gument to the)-.18 F F2<ad70>2.851 E F0 .351(option to the)2.851 F F2
(hash)2.851 E F0 -.2(bu)2.851 G .351(iltin com-).2 F(mand)144 244.8 Q
(iltin command).2 E 32.5<8373>108 232.8 S .45
(pecifying a \214lename containing a slash as an ar)-32.5 F .449
(gument to the)-.18 F F2<ad70>2.949 E F0 .449(option to the)2.949 F F2
(hash)2.949 E F0 -.2(bu)2.949 G .449(iltin com-).2 F(mand)144 244.8 Q
32.5<8369>108 261.6 S(mporting function de\214nitions from the shell en)
-32.5 E(vironment at startup)-.4 E 32.5<8370>108 278.4 S(arsing the v)
-32.5 E(alue of)-.25 E F3(SHELLOPTS)2.5 E F0(from the shell en)2.25 E
@ -260,7 +260,7 @@ ng the >, >|, <>, >&, &>, and >> redirection operators)-32.5 E 32.5
(iltin command to replace the shell with another command).2 E 32.5<8361>
108 328.8 S(dding or deleting b)-32.5 E(uiltin commands with the)-.2 E
F2<ad66>2.5 E F0(and)2.5 E F2<ad64>2.5 E F0(options to the)2.5 E F2
(enable)2.5 E F0 -.2(bu)2.5 G(iltin command).2 E 32.5<8355>108 345.6 S
(enable)2.5 E F0 -.2(bu)2.5 G(iltin command).2 E 32.5<8375>108 345.6 S
(sing the)-32.5 E F2(enable)2.5 E F0 -.2(bu)2.5 G
(iltin command to enable disabled shell b).2 E(uiltins)-.2 E 32.5<8373>
108 362.4 S(pecifying the)-32.5 E F2<ad70>2.5 E F0(option to the)2.5 E

View File

@ -1,10 +1,10 @@
@ignore
Copyright (C) 1988-2009 Free Software Foundation, Inc.
Copyright (C) 1988-2011 Free Software Foundation, Inc.
@end ignore
@set LASTCHANGE Wed Dec 23 16:29:41 EST 2009
@set LASTCHANGE Tue Dec 28 13:41:22 EST 2010
@set EDITION 4.1
@set VERSION 4.1
@set UPDATED 23 December 2009
@set UPDATED-MONTH December 2009
@set EDITION 4.2
@set VERSION 4.2
@set UPDATED 28 December 2010
@set UPDATED-MONTH December 2010

View File

@ -0,0 +1,67 @@
#From: "dennis" <dennis@netstrata.com>
#To: <bash-maintainers@gnu.org>
#Subject: New example script: bash-hexdump
#Date: Mon, 4 Jan 2010 22:48:19 -0700
#Message-ID: <6dbec42d$64fcdbd2$4a32cf2d$@com>
#I've written a script that functions like "hexdump -C" or "hd". If you'd
#like to include it in a future distribution of example Bash scripts, I have
#included it here:
#!/bin/bash
# bash-hexdump# pure Bash, no externals
# by Dennis Williamson - 2010-01-04
# in response to
http://stackoverflow.com/questions/2003803/show-hexadecimal-numbers-of-a-file
# usage: bash-hexdump file
saveIFS="$IFS"
IFS="" # disables interpretation of \t, \n and space
saveLANG="$LANG"
LANG=C # allows characters > 0x7F
bytecount=0
valcount=0
printf "%08x " $bytecount
while read -d '' -r -n 1 char # -d '' allows newlines, -r allows \
do
((bytecount++))
# for information about the apostrophe in this printf command, see
# http://www.opengroup.org/onlinepubs/009695399/utilities/printf.html
printf -v val "%02x" "'$char"
echo -n "$val "
((valcount++))
if [[ "$val" < 20 || "$val" > 7e ]]
then
string+="." # show unprintable characters as a dot
else
string+=$char
fi
if (( bytecount % 8 == 0 )) # add a space down the middle
then
echo -n " "
fi
if (( bytecount % 16 == 0 )) # print 16 values per line
then
echo "|$string|"
string=''
valcount=0
printf "%08x " $bytecount
fi
done < "$1"
if [[ "$string" != "" ]] # if the last line wasn't full, pad it out
then
length=${#string}
if (( length > 7 ))
then
((length--))
fi
(( length += (16 - valcount) * 3 + 4))
printf "%${length}s\n" "|$string|"
printf "%08x " $bytecount
fi
echo
LANG="$saveLANG";
IFS="$saveIFS"
exit 0

View File

@ -1,56 +1,57 @@
#!/bin/bash
#
# The Bash shell script executes a command with a time-out.
# Upon time-out expiration SIGTERM (15) is sent to the process. If the signal
# is blocked, then the subsequent SIGKILL (9) terminates it.
#
# The Bash script executes a command with a time-out.
# Based on the Bash documentation example.
# Hello Chet,
# please find attached a "little easier" :-) to comprehend
# time-out example. If you find it suitable, feel free to include
# anywhere: the very same logic as in the original examples/scripts, a
# little more transparent implementation to my taste.
#
# Dmitry V Golovashkin <Dmitry.Golovashkin@sas.com>
# Upon time-out expiration SIGTERM (15) is sent to the process. If the signal
# is blocked, then the subsequent SIGKILL (9) terminates it.
# Dmitry V Golovashkin (E-mail: dvg@ieee.org)
#
script_name="${0##*/}"
scriptName="${0##*/}"
# Default values.
readonly param_timeout=5
readonly param_interval=1
readonly param_delay=1
declare -i DEFAULT_TIMEOUT=9
declare -i DEFAULT_INTERVAL=1
declare -i DEFAULT_DELAY=1
declare -i timeout=param_timeout
declare -i interval=param_interval
declare -i delay=param_delay
# Timeout.
declare -i timeout=DEFAULT_TIMEOUT
# Interval between checks if the process is still alive.
declare -i interval=DEFAULT_INTERVAL
# Delay between posting the SIGTERM signal and destroying the process by SIGKILL.
declare -i delay=DEFAULT_DELAY
blue="$(tput setaf 4)"
bold_red="$(tput bold; tput setaf 1)"
off="$(tput sgr0)"
function printUsage() {
cat <<EOF
function print_usage() {
cat <<EOF
Synopsis
$scriptName [-t timeout] [-i interval] [-d delay] command
Execute a command with a time-out.
Upon time-out expiration SIGTERM (15) is sent to the process. If SIGTERM
signal is blocked, then the subsequent SIGKILL (9) terminates it.
Synopsis: $script_name [-t timeout] [-i interval] [-d delay] command
-t timeout
Number of seconds to wait for command completion.
Default value: $DEFAULT_TIMEOUT seconds.
Executes the command with a time-out. Upon time-out expiration SIGTERM (15) is
sent to the process. If SIGTERM signal is blocked, then the subsequent SIGKILL
(9) terminates it.
-i interval
Interval between checks if the process is still alive.
Positive integer, default value: $DEFAULT_INTERVAL seconds.
$blue-t timeout$off
Number of seconds to wait for command completion.
Default value: $param_timeout seconds. In some practical situations
this value ${bold_red}must$off be increased (for instance -t 180) to allow
the command to complete.
-d delay
Delay between posting the SIGTERM signal and destroying the
process by SIGKILL. Default value: $DEFAULT_DELAY seconds.
$blue-i interval$off
Interval between checks if the process is still alive.
Positive integer, default value: $param_interval seconds.
Default value is OK for most situations.
$blue-d delay$off
Delay between posting the SIGTERM signal and destroying the process by
SIGKILL. Default value: $param_delay seconds.
Default value is OK for most situations.
As of today, Bash does not support floating point arithmetic (sleep does),
therefore all delay/time values must be integers.
therefore all time values must be integers.
Dmitry Golovashkin (E-mail: dvg@ieee.org)
EOF
exit 1 # No useful work was done.
}
# Options.
@ -59,7 +60,7 @@ while getopts ":t:i:d:" option; do
t) timeout=$OPTARG ;;
i) interval=$OPTARG ;;
d) delay=$OPTARG ;;
*) printUsage; exit 1 ;;
*) print_usage ;;
esac
done
shift $((OPTIND - 1))
@ -67,11 +68,10 @@ shift $((OPTIND - 1))
# $# should be at least 1 (the command to execute), however it may be strictly
# greater than 1 if the command itself has options.
if (($# == 0 || interval <= 0)); then
printUsage
exit 1
print_usage
fi
# kill -0 pid Exit code indicates if a signal may be sent to $pid process.
# kill -0 pid Exit code indicates if a signal may be sent to "pid" process.
(
((t = timeout))
@ -89,3 +89,4 @@ fi
) 2> /dev/null &
exec "$@"

View File

@ -1,6 +1,7 @@
if [ -z "$PS1" ]; then
return
fi
case $- in
*i*) ;;
*) return ;;
esac
# bogus
if [ -f /unix ] ; then

View File

@ -1,6 +1,6 @@
/* execute_cmd.c -- Execute a COMMAND structure. */
/* Copyright (C) 1987-2009 Free Software Foundation, Inc.
/* Copyright (C) 1987-2010 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@ -98,6 +98,7 @@ extern int errno;
# include "bashhist.h"
#endif
extern int dollar_dollar_pid;
extern int posixly_correct;
extern int expand_aliases;
extern int autocd;
@ -112,6 +113,7 @@ extern pid_t last_command_subst_pid;
extern sh_builtin_func_t *last_shell_builtin, *this_shell_builtin;
extern char **subshell_argv, **subshell_envp;
extern int subshell_argc;
extern time_t shell_start_time;
#if 0
extern char *glob_argv_flags;
#endif
@ -135,6 +137,7 @@ static int builtin_status __P((int));
static int execute_for_command __P((FOR_COM *));
#if defined (SELECT_COMMAND)
static int displen __P((const char *));
static int print_index_and_element __P((int, int, WORD_LIST *));
static void indent __P((int, int));
static void print_select_list __P((WORD_LIST *, int, int, int));
@ -178,7 +181,7 @@ static void execute_subshell_builtin_or_function __P((WORD_LIST *, REDIRECT *,
int, int, int,
struct fd_bitmap *,
int));
static void execute_disk_command __P((WORD_LIST *, REDIRECT *, char *,
static int execute_disk_command __P((WORD_LIST *, REDIRECT *, char *,
int, int, int, struct fd_bitmap *, int));
static char *getinterp __P((char *, int, int *));
@ -253,6 +256,8 @@ SHELL_VAR *this_shell_function;
/* If non-zero, matches in case and [[ ... ]] are case-insensitive */
int match_ignore_case = 0;
int executing_command_builtin = 0;
struct stat SB; /* used for debugging */
static int special_builtin_failed;
@ -270,8 +275,10 @@ static int showing_function_line;
static int line_number_for_err_trap;
/* A sort of function nesting level counter */
static int funcnest = 0;
int funcnest_max = 0; /* XXX - for bash-4.2 */
int funcnest = 0;
int funcnest_max = 0; /* XXX - bash-4.2 */
int lastpipe_opt = 0;
struct fd_bitmap *current_fds_to_close = (struct fd_bitmap *)NULL;
@ -603,19 +610,17 @@ execute_command_internal (command, asynchronous, pipe_in, pipe_out,
invert = (command->flags & CMD_INVERT_RETURN) != 0;
ignore_return = (command->flags & CMD_IGNORE_RETURN) != 0;
last_command_exit_value = wait_for (paren_pid);
exec_result = wait_for (paren_pid);
/* If we have to, invert the return value. */
if (invert)
exec_result = ((last_command_exit_value == EXECUTION_SUCCESS)
exec_result = ((exec_result == EXECUTION_SUCCESS)
? EXECUTION_FAILURE
: EXECUTION_SUCCESS);
else
exec_result = last_command_exit_value;
last_command_exit_value = exec_result;
if (user_subshell && was_error_trap && ignore_return == 0 && invert == 0 && exec_result != EXECUTION_SUCCESS)
{
last_command_exit_value = exec_result;
save_line_number = line_number;
line_number = line_number_for_err_trap;
run_error_trap ();
@ -624,12 +629,11 @@ execute_command_internal (command, asynchronous, pipe_in, pipe_out,
if (user_subshell && ignore_return == 0 && invert == 0 && exit_immediately_on_error && exec_result != EXECUTION_SUCCESS)
{
last_command_exit_value = exec_result;
run_pending_traps ();
jump_to_top_level (ERREXIT);
}
return (last_command_exit_value = exec_result);
return (last_command_exit_value);
}
else
{
@ -677,6 +681,7 @@ execute_command_internal (command, asynchronous, pipe_in, pipe_out,
if (redirection_undo_list)
{
/* XXX - why copy here? */
my_undo_list = (REDIRECT *)copy_redirects (redirection_undo_list);
dispose_redirects (redirection_undo_list);
redirection_undo_list = (REDIRECT *)NULL;
@ -686,6 +691,7 @@ execute_command_internal (command, asynchronous, pipe_in, pipe_out,
if (exec_redirection_undo_list)
{
/* XXX - why copy here? */
exec_undo_list = (REDIRECT *)copy_redirects (exec_redirection_undo_list);
dispose_redirects (exec_redirection_undo_list);
exec_redirection_undo_list = (REDIRECT *)NULL;
@ -1182,7 +1188,7 @@ time_command (command, asynchronous, pipe_in, pipe_out, fds_to_close)
int asynchronous, pipe_in, pipe_out;
struct fd_bitmap *fds_to_close;
{
int rv, posix_time, old_flags;
int rv, posix_time, old_flags, nullcmd;
time_t rs, us, ss;
int rsf, usf, ssf;
int cpu;
@ -1218,6 +1224,20 @@ time_command (command, asynchronous, pipe_in, pipe_out, fds_to_close)
posix_time = (command->flags & CMD_TIME_POSIX);
nullcmd = (command == 0) || (command->type == cm_simple && command->value.Simple->words == 0 && command->value.Simple->redirects == 0);
if (posixly_correct && nullcmd)
{
#if defined (HAVE_GETRUSAGE)
selfb.ru_utime.tv_sec = kidsb.ru_utime.tv_sec = selfb.ru_stime.tv_sec = kidsb.ru_stime.tv_sec = 0;
selfb.ru_utime.tv_usec = kidsb.ru_utime.tv_usec = selfb.ru_stime.tv_usec = kidsb.ru_stime.tv_usec = 0;
before.tv_sec = shell_start_time;
before.tv_usec = 0;
#else
before.tms_utime = before.tms_stime = before.tms_cutime = before.tms_cstime = 0;
tbefore = shell_start_time;
#endif
}
old_flags = command->flags;
command->flags &= ~(CMD_TIME_PIPELINE|CMD_TIME_POSIX);
rv = execute_command_internal (command, asynchronous, pipe_in, pipe_out, fds_to_close);
@ -1271,8 +1291,12 @@ time_command (command, asynchronous, pipe_in, pipe_out, fds_to_close)
if (posix_time)
time_format = POSIX_TIMEFORMAT;
else if ((time_format = get_string_value ("TIMEFORMAT")) == 0)
time_format = BASH_TIMEFORMAT;
{
if (posixly_correct && nullcmd)
time_format = "user\t%2lU\nsys\t%2lS";
else
time_format = BASH_TIMEFORMAT;
}
if (time_format && *time_format)
print_formatted_time (stderr, time_format, rs, rsf, us, usf, ss, ssf, cpu);
@ -1293,7 +1317,7 @@ execute_in_subshell (command, asynchronous, pipe_in, pipe_out, fds_to_close)
int user_subshell, return_code, function_value, should_redir_stdin, invert;
int ois, user_coproc;
int result;
COMMAND *tcom;
volatile COMMAND *tcom;
USE_VAR(user_subshell);
USE_VAR(user_coproc);
@ -1367,7 +1391,11 @@ execute_in_subshell (command, asynchronous, pipe_in, pipe_out, fds_to_close)
reset_terminating_signals (); /* in sig.c */
/* Cancel traps, in trap.c. */
restore_original_signals ();
/* Reset the signal handlers in the child, but don't free the
trap strings. Set a flag noting that we have to free the
trap strings if we run trap to change a signal disposition. */
reset_signal_handlers ();
subshell_environment |= SUBSHELL_RESETTRAP;
/* Make sure restore_original_signals doesn't undo the work done by
make_child to ensure that asynchronous children are immune to SIGINT
@ -1524,7 +1552,7 @@ static struct cpelement *cpl_search __P((pid_t));
static struct cpelement *cpl_searchbyname __P((char *));
static void cpl_prune __P((void));
Coproc sh_coproc = { 0, NO_PID, -1, -1, 0, 0 };
Coproc sh_coproc = { 0, NO_PID, -1, -1, 0, 0, 0, 0 };
cplist_t coproc_list = {0, 0, 0};
@ -2046,6 +2074,22 @@ execute_coproc (command, pipe_in, pipe_out, fds_to_close)
}
#endif
static void
restore_stdin (s)
int s;
{
dup2 (s, 0);
close (s);
}
/* Catch-all cleanup function for lastpipe code for unwind-protects */
static void
lastpipe_cleanup (s)
int s;
{
unfreeze_jobs_list ();
}
static int
execute_pipeline (command, asynchronous, pipe_in, pipe_out, fds_to_close)
COMMAND *command;
@ -2053,8 +2097,10 @@ execute_pipeline (command, asynchronous, pipe_in, pipe_out, fds_to_close)
struct fd_bitmap *fds_to_close;
{
int prev, fildes[2], new_bitmap_size, dummyfd, ignore_return, exec_result;
int lstdin, lastpipe_flag, lastpipe_jid;
COMMAND *cmd;
struct fd_bitmap *fd_bitmap;
pid_t lastpid;
#if defined (JOB_CONTROL)
sigset_t set, oset;
@ -2144,11 +2190,41 @@ execute_pipeline (command, asynchronous, pipe_in, pipe_out, fds_to_close)
cmd = cmd->value.Connection->second;
}
lastpid = last_made_pid;
/* Now execute the rightmost command in the pipeline. */
if (ignore_return && cmd)
cmd->flags |= CMD_IGNORE_RETURN;
lastpipe_flag = 0;
begin_unwind_frame ("lastpipe-exec");
lstdin = -1;
/* If the `lastpipe' option is set with shopt, and job control is not
enabled, execute the last element of non-async pipelines in the
current shell environment. */
if (lastpipe_opt && job_control == 0 && asynchronous == 0 && pipe_out == NO_PIPE && prev > 0)
{
lstdin = move_to_high_fd (0, 0, 255);
if (lstdin > 0)
{
do_piping (prev, pipe_out);
prev = NO_PIPE;
add_unwind_protect (restore_stdin, lstdin);
lastpipe_flag = 1;
freeze_jobs_list ();
lastpipe_jid = stop_pipeline (0, (COMMAND *)NULL); /* XXX */
add_unwind_protect (lastpipe_cleanup, lastpipe_jid);
}
cmd->flags |= CMD_LASTPIPE;
}
if (prev >= 0)
add_unwind_protect (close, prev);
exec_result = execute_command_internal (cmd, asynchronous, prev, pipe_out, fds_to_close);
if (lstdin > 0)
restore_stdin (lstdin);
if (prev >= 0)
close (prev);
@ -2157,6 +2233,21 @@ execute_pipeline (command, asynchronous, pipe_in, pipe_out, fds_to_close)
#endif
QUIT;
if (lastpipe_flag)
{
#if defined (JOB_CONTROL)
append_process (savestring (the_printed_command), dollar_dollar_pid, exec_result, lastpipe_jid);
#endif
lstdin = wait_for (lastpid);
#if defined (JOB_CONTROL)
exec_result = job_exit_status (lastpipe_jid);
#endif
unfreeze_jobs_list ();
}
discard_unwind_frame ("lastpipe-exec");
return (exec_result);
}
@ -2166,7 +2257,6 @@ execute_connection (command, asynchronous, pipe_in, pipe_out, fds_to_close)
int asynchronous, pipe_in, pipe_out;
struct fd_bitmap *fds_to_close;
{
REDIRECT *rp;
COMMAND *tc, *second;
int ignore_return, exec_result, was_error_trap, invert;
volatile int save_line_number;
@ -2181,8 +2271,6 @@ execute_connection (command, asynchronous, pipe_in, pipe_out, fds_to_close)
if (tc == 0)
return (EXECUTION_SUCCESS);
rp = tc->redirects;
if (ignore_return)
tc->flags |= CMD_IGNORE_RETURN;
tc->flags |= CMD_AMPERSAND;
@ -2619,6 +2707,28 @@ static int LINES, COLS, tabsize;
: ((s < 100000) ? 5 \
: 6)))))
static int
displen (s)
const char *s;
{
#if defined (HANDLE_MULTIBYTE)
wchar_t *wcstr;
size_t wclen, slen;
wcstr = 0;
slen = mbstowcs (wcstr, s, 0);
if (slen == -1)
slen = 0;
wcstr = (wchar_t *)xmalloc (sizeof (wchar_t) * (slen + 1));
mbstowcs (wcstr, s, slen + 1);
wclen = wcswidth (wcstr, slen);
free (wcstr);
return ((int)wclen);
#else
return (STRLEN (s));
#endif
}
static int
print_index_and_element (len, ind, list)
int len, ind;
@ -2632,7 +2742,7 @@ print_index_and_element (len, ind, list)
for (i = ind, l = list; l && --i; l = l->next)
;
fprintf (stderr, "%*d%s%s", len, ind, RP_SPACE, l->word->word);
return (STRLEN (l->word->word));
return (displen (l->word->word));
}
static void
@ -2719,8 +2829,10 @@ select_query (list, list_len, prompt, print_menu)
WORD_LIST *l;
char *repl_string, *t;
#if 0
t = get_string_value ("LINES");
LINES = (t && *t) ? atoi (t) : 24;
#endif
t = get_string_value ("COLUMNS");
COLS = (t && *t) ? atoi (t) : 80;
@ -2736,7 +2848,7 @@ select_query (list, list_len, prompt, print_menu)
max_elem_len = 0;
for (l = list; l; l = l->next)
{
len = STRLEN (l->word->word);
len = displen (l->word->word);
if (len > max_elem_len)
max_elem_len = len;
}
@ -2751,7 +2863,7 @@ select_query (list, list_len, prompt, print_menu)
fflush (stderr);
QUIT;
if (read_builtin ((WORD_LIST *)NULL) == EXECUTION_FAILURE)
if (read_builtin ((WORD_LIST *)NULL) != EXECUTION_SUCCESS)
{
putchar ('\n');
return ((char *)NULL);
@ -3533,6 +3645,7 @@ execute_simple_command (simple_command, pipe_in, pipe_out, async, fds_to_close)
pid_t old_last_async_pid;
sh_builtin_func_t *builtin;
SHELL_VAR *func;
volatile int old_builtin, old_command_builtin;
result = EXECUTION_SUCCESS;
special_builtin_failed = builtin_is_special = 0;
@ -3623,6 +3736,10 @@ execute_simple_command (simple_command, pipe_in, pipe_out, async, fds_to_close)
}
else
{
/* Don't let simple commands that aren't the last command in a
pipeline change $? for the rest of the pipeline (or at all). */
if (pipe_out != NO_PIPE)
result = last_command_exit_value;
close_pipes (pipe_in, pipe_out);
#if defined (PROCESS_SUBSTITUTION) && defined (HAVE_DEV_FD)
unlink_fifo_list ();
@ -3778,12 +3895,20 @@ run_builtin:
if (builtin || func)
{
if (builtin)
unwind_protect_int (executing_builtin); /* modified in execute_builtin */
{
old_builtin = executing_builtin;
old_command_builtin = executing_command_builtin;
unwind_protect_int (executing_builtin); /* modified in execute_builtin */
unwind_protect_int (executing_command_builtin); /* ditto */
}
if (already_forked)
{
/* reset_terminating_signals (); */ /* XXX */
/* Cancel traps, in trap.c. */
restore_original_signals ();
/* Reset the signal handlers in the child, but don't free the
trap strings. Set a flag noting that we have to free the
trap strings if we run trap to change a signal disposition. */
reset_signal_handlers ();
subshell_environment |= SUBSHELL_RESETTRAP;
if (async)
{
@ -3849,7 +3974,7 @@ run_builtin:
simple_command->flags &= ~CMD_NO_FORK;
#endif
execute_disk_command (words, simple_command->redirects, command_line,
result = execute_disk_command (words, simple_command->redirects, command_line,
pipe_in, pipe_out, async, fds_to_close,
simple_command->flags);
@ -3857,6 +3982,11 @@ run_builtin:
bind_lastarg (lastarg);
FREE (command_line);
dispose_words (words);
if (builtin)
{
executing_builtin = old_builtin;
executing_command_builtin = old_command_builtin;
}
discard_unwind_frame ("simple-command");
this_command_name = (char *)NULL; /* points to freed memory now */
return (result);
@ -3962,6 +4092,7 @@ execute_builtin (builtin, words, flags, subshell)
}
executing_builtin++;
executing_command_builtin |= builtin == command_builtin;
result = ((*builtin) (words->next));
/* This shouldn't happen, but in case `return' comes back instead of
@ -4004,20 +4135,21 @@ execute_function (var, words, flags, fds_to_close, async, subshell)
char *debug_trap, *error_trap, *return_trap;
#if defined (ARRAY_VARS)
SHELL_VAR *funcname_v, *nfv, *bash_source_v, *bash_lineno_v;
ARRAY *funcname_a, *bash_source_a, *bash_lineno_a;
ARRAY *funcname_a;
volatile ARRAY *bash_source_a;
volatile ARRAY *bash_lineno_a;
#endif
FUNCTION_DEF *shell_fn;
char *sfile, *t;
USE_VAR(fc);
#if 0 /* for bash-4.2 */
if (funcnest_max > 0 && funcnest >= funcnest_max)
{
internal_error ("%s: maximum function nesting level exceeded (%d)", var->name, funcnest);
funcnest = 0; /* XXX - should we reset it somewhere else? */
jump_to_top_level (DISCARD);
}
#endif
#if defined (ARRAY_VARS)
GET_ARRAY_FROM_VAR ("FUNCNAME", funcname_v, funcname_a);
@ -4343,17 +4475,28 @@ execute_builtin_or_function (words, builtin, var, redirects,
{
int result;
REDIRECT *saved_undo_list;
sh_builtin_func_t *saved_this_shell_builtin;
#if defined (PROCESS_SUBSTITUTION)
int ofifo, nfifo, osize;
char *ofifo_list;
#endif
#if defined (PROCESS_SUBSTITUTION)
ofifo = num_fifos ();
ofifo_list = copy_fifo_list (&osize);
#endif
if (do_redirections (redirects, RX_ACTIVE|RX_UNDOABLE) != 0)
{
cleanup_redirects (redirection_undo_list);
redirection_undo_list = (REDIRECT *)NULL;
dispose_exec_redirects ();
#if defined (PROCESS_SUBSTITUTION)
free (ofifo_list);
#endif
return (EX_REDIRFAIL); /* was EXECUTION_FAILURE */
}
saved_this_shell_builtin = this_shell_builtin;
saved_undo_list = redirection_undo_list;
/* Calling the "exec" builtin changes redirections forever. */
@ -4393,11 +4536,18 @@ execute_builtin_or_function (words, builtin, var, redirects,
and preserve the redirections. */
if (builtin == command_builtin && this_shell_builtin == exec_builtin)
{
int discard;
discard = 0;
if (saved_undo_list)
dispose_redirects (saved_undo_list);
{
dispose_redirects (saved_undo_list);
discard = 1;
}
redirection_undo_list = exec_redirection_undo_list;
saved_undo_list = exec_redirection_undo_list = (REDIRECT *)NULL;
discard_unwind_frame ("saved_redirects");
if (discard)
discard_unwind_frame ("saved redirects");
}
if (saved_undo_list)
@ -4412,6 +4562,14 @@ execute_builtin_or_function (words, builtin, var, redirects,
redirection_undo_list = (REDIRECT *)NULL;
}
#if defined (PROCESS_SUBSTITUTION)
/* Close any FIFOs created by this builtin or function. */
nfifo = num_fifos ();
if (nfifo > ofifo)
close_new_fifos (ofifo_list, osize);
free (ofifo_list);
#endif
return (result);
}
@ -4457,7 +4615,7 @@ setup_async_signals ()
# define NOTFOUND_HOOK "command_not_found_handle"
#endif
static void
static int
execute_disk_command (words, redirects, command_line, pipe_in, pipe_out,
async, fds_to_close, cmdflags)
WORD_LIST *words;
@ -4468,7 +4626,7 @@ execute_disk_command (words, redirects, command_line, pipe_in, pipe_out,
int cmdflags;
{
char *pathname, *command, **args;
int nofork;
int nofork, result;
pid_t pid;
SHELL_VAR *hookf;
WORD_LIST *wl;
@ -4476,13 +4634,14 @@ execute_disk_command (words, redirects, command_line, pipe_in, pipe_out,
nofork = (cmdflags & CMD_NO_FORK); /* Don't fork, just exec, if no pipes */
pathname = words->word->word;
result = EXECUTION_SUCCESS;
#if defined (RESTRICTED_SHELL)
command = (char *)NULL;
if (restricted && mbschr (pathname, '/'))
{
internal_error (_("%s: restricted: cannot specify `/' in command names"),
pathname);
last_command_exit_value = EXECUTION_FAILURE;
result = last_command_exit_value = EXECUTION_FAILURE;
/* If we're not going to fork below, we must already be in a child
process or a context in which it's safe to call exit(2). */
@ -4522,6 +4681,7 @@ execute_disk_command (words, redirects, command_line, pipe_in, pipe_out,
#endif
#endif
reset_terminating_signals (); /* XXX */
/* Cancel traps, in trap.c. */
restore_original_signals ();
@ -4571,6 +4731,9 @@ execute_disk_command (words, redirects, command_line, pipe_in, pipe_out,
hookf = find_function (NOTFOUND_HOOK);
if (hookf == 0)
{
/* Make sure filenames are displayed using printable characters */
if (ansic_shouldquote (pathname))
pathname = ansic_quote (pathname, 0, NULL);
internal_error (_("%s: command not found"), pathname);
exit (EX_NOTFOUND); /* Posix.2 says the exit status is 127 */
}
@ -4595,6 +4758,7 @@ parent_return:
unlink_fifo_list ();
#endif
FREE (command);
return (result);
}
}
@ -4793,7 +4957,11 @@ shell_execve (command, args, env)
if (i != ENOEXEC)
{
if (file_isdir (command))
#if defined (EISDIR)
internal_error (_("%s: %s"), command, strerror (EISDIR));
#else
internal_error (_("%s: is a directory"), command);
#endif
else if (executable_file (command) == 0)
{
errno = i;
@ -4990,6 +5158,10 @@ do_piping (pipe_in, pipe_out)
dup_error (pipe_in, 0);
if (pipe_in > 0)
close (pipe_in);
#ifdef __CYGWIN__
/* Let stdio know the fd may have changed from text to binary mode. */
freopen (NULL, "r", stdin);
#endif /* __CYGWIN__ */
}
if (pipe_out != NO_PIPE)
{
@ -5005,5 +5177,11 @@ do_piping (pipe_in, pipe_out)
if (dup2 (1, 2) < 0)
dup_error (1, 2);
}
#ifdef __CYGWIN__
/* Let stdio know the fd may have changed from text to binary mode, and
make sure to preserve stdout line buffering. */
freopen (NULL, "w", stdout);
sh_setlinebuf (stdout);
#endif /* __CYGWIN__ */
}
}

178
expr.c
View File

@ -1,6 +1,6 @@
/* expr.c -- arithmetic expression evaluation. */
/* Copyright (C) 1990-2009 Free Software Foundation, Inc.
/* Copyright (C) 1990-2010 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@ -137,6 +137,28 @@
highest precedence. */
#define EXP_HIGHEST expcomma
#ifndef MAX_INT_LEN
# define MAX_INT_LEN 32
#endif
struct lvalue
{
char *tokstr; /* possibly-rewritten lvalue if not NULL */
intmax_t tokval; /* expression evaluated value */
SHELL_VAR *tokvar; /* variable described by array or var reference */
intmax_t ind; /* array index if not -1 */
};
/* A structure defining a single expression context. */
typedef struct {
int curtok, lasttok;
char *expression, *tp, *lasttp;
intmax_t tokval;
char *tokstr;
int noeval;
struct lvalue lval;
} EXPR_CONTEXT;
static char *expression; /* The current expression */
static char *tp; /* token lexical position */
static char *lasttp; /* pointer to last token position */
@ -148,10 +170,17 @@ static intmax_t tokval; /* current token value */
static int noeval; /* set to 1 if no assignment to be done */
static procenv_t evalbuf;
static struct lvalue curlval = {0, 0, 0, -1};
static struct lvalue lastlval = {0, 0, 0, -1};
static int _is_arithop __P((int));
static void readtok __P((void)); /* lexical analyzer */
static intmax_t expr_streval __P((char *, int));
static void init_lvalue __P((struct lvalue *));
static struct lvalue *alloc_lvalue __P((void));
static void free_lvalue __P((struct lvalue *));
static intmax_t expr_streval __P((char *, int, struct lvalue *));
static intmax_t strlong __P((char *));
static void evalerror __P((const char *));
@ -159,6 +188,7 @@ static void pushexp __P((void));
static void popexp __P((void));
static void expr_unwind __P((void));
static void expr_bind_variable __P((char *, char *));
static void expr_bind_array_element __P((char *, arrayind_t, char *));
static intmax_t subexpr __P((char *));
@ -179,23 +209,6 @@ static intmax_t exppower __P((void));
static intmax_t exp1 __P((void));
static intmax_t exp0 __P((void));
/* A structure defining a single expression context. */
typedef struct {
int curtok, lasttok;
char *expression, *tp, *lasttp;
intmax_t tokval;
char *tokstr;
int noeval;
} EXPR_CONTEXT;
#ifdef INCLUDE_UNUSED
/* Not used yet. */
typedef struct {
char *tokstr;
intmax_t tokval;
} LVALUE;
#endif
/* Global var which contains the stack of expression contexts. */
static EXPR_CONTEXT **expr_stack;
static int expr_depth; /* Location in the stack. */
@ -217,6 +230,7 @@ extern const char * const bash_badsub_errmsg;
(X)->tokval = tokval; \
(X)->tokstr = tokstr; \
(X)->noeval = noeval; \
(X)->lval = curlval; \
} while (0)
#define RESTORETOK(X) \
@ -228,6 +242,7 @@ extern const char * const bash_badsub_errmsg;
tokval = (X)->tokval; \
tokstr = (X)->tokstr; \
noeval = (X)->noeval; \
curlval = (X)->lval; \
} while (0)
/* Push and save away the contents of the globals describing the
@ -298,6 +313,32 @@ expr_bind_variable (lhs, rhs)
stupidly_hack_special_variables (lhs);
}
/* Rewrite tok, which is of the form vname[expression], to vname[ind], where
IND is the already-calculated value of expression. */
static void
expr_bind_array_element (tok, ind, rhs)
char *tok;
arrayind_t ind;
char *rhs;
{
char *lhs, *vname;
size_t llen;
char ibuf[INT_STRLEN_BOUND (arrayind_t) + 1], *istr;
istr = fmtumax (ind, 10, ibuf, sizeof (ibuf), 0);
vname = array_variable_name (tok, (char **)NULL, (int *)NULL);
llen = strlen (vname) + sizeof (ibuf) + 3;
lhs = xmalloc (llen);
sprintf (lhs, "%s[%s]", vname, istr); /* XXX */
expr_bind_variable (lhs, rhs);
/*itrace("expr_bind_array_element: %s=%s", lhs, rhs);*/
free (vname);
free (lhs);
}
/* Evaluate EXPR, and return the arithmetic result. If VALIDP is
non-null, a zero is stored into the location to which it points
if the expression is invalid, non-zero otherwise. If a non-zero
@ -364,12 +405,14 @@ subexpr (expr)
return (0);
pushexp ();
curtok = lasttok = 0;
expression = savestring (expr);
tp = expression;
curtok = lasttok = 0;
tokstr = (char *)NULL;
tokval = 0;
init_lvalue (&curlval);
lastlval = curlval;
readtok ();
@ -406,6 +449,7 @@ expassign ()
{
register intmax_t value;
char *lhs, *rhs;
arrayind_t lind;
value = expcond ();
if (curtok == EQ || curtok == OP_ASSIGN)
@ -425,6 +469,8 @@ expassign ()
}
lhs = savestring (tokstr);
/* save ind in case rhs is string var and evaluation overwrites it */
lind = curlval.ind;
readtok ();
value = expassign ();
@ -476,7 +522,12 @@ expassign ()
rhs = itos (value);
if (noeval == 0)
expr_bind_variable (lhs, rhs);
{
if (lind != -1)
expr_bind_array_element (lhs, lind, rhs);
else
expr_bind_variable (lhs, rhs);
}
free (rhs);
free (lhs);
FREE (tokstr);
@ -801,6 +852,16 @@ exp1 ()
readtok ();
val = ~exp1 ();
}
else if (curtok == MINUS)
{
readtok ();
val = - exp1 ();
}
else if (curtok == PLUS)
{
readtok ();
val = exp1 ();
}
else
val = exp0 ();
@ -828,23 +889,18 @@ exp0 ()
v2 = tokval + ((stok == PREINC) ? 1 : -1);
vincdec = itos (v2);
if (noeval == 0)
expr_bind_variable (tokstr, vincdec);
{
if (curlval.ind != -1)
expr_bind_array_element (curlval.tokstr, curlval.ind, vincdec);
else
expr_bind_variable (tokstr, vincdec);
}
free (vincdec);
val = v2;
curtok = NUM; /* make sure --x=7 is flagged as an error */
readtok ();
}
else if (curtok == MINUS)
{
readtok ();
val = - exp0 ();
}
else if (curtok == PLUS)
{
readtok ();
val = exp0 ();
}
else if (curtok == LPAR)
{
readtok ();
@ -873,12 +929,18 @@ exp0 ()
/* restore certain portions of EC */
tokstr = ec.tokstr;
noeval = ec.noeval;
curlval = ec.lval;
lasttok = STR; /* ec.curtok */
v2 = val + ((stok == POSTINC) ? 1 : -1);
vincdec = itos (v2);
if (noeval == 0)
expr_bind_variable (tokstr, vincdec);
{
if (curlval.ind != -1)
expr_bind_array_element (curlval.tokstr, curlval.ind, vincdec);
else
expr_bind_variable (tokstr, vincdec);
}
free (vincdec);
curtok = NUM; /* make sure x++=7 is flagged as an error */
}
@ -899,14 +961,44 @@ exp0 ()
return (val);
}
static void
init_lvalue (lv)
struct lvalue *lv;
{
lv->tokstr = 0;
lv->tokvar = 0;
lv->tokval = lv->ind = -1;
}
static struct lvalue *
alloc_lvalue ()
{
struct lvalue *lv;
lv = xmalloc (sizeof (struct lvalue));
init_lvalue (lv);
return (lv);
}
static void
free_lvalue (lv)
struct lvalue *lv;
{
free (lv); /* should be inlined */
}
static intmax_t
expr_streval (tok, e)
expr_streval (tok, e, lvalue)
char *tok;
int e;
struct lvalue *lvalue;
{
SHELL_VAR *v;
char *value;
intmax_t tval;
#if defined (ARRAY_VARS)
arrayind_t ind;
#endif
/* [[[[[ */
#if defined (ARRAY_VARS)
@ -941,18 +1033,27 @@ expr_streval (tok, e)
jump_to_top_level (FORCE_EOF);
}
ind = -1;
#if defined (ARRAY_VARS)
/* Second argument of 0 to get_array_value means that we don't allow
references like array[@]. In this case, get_array_value is just
like get_variable_value in that it does not return newly-allocated
memory or quote the results. */
value = (e == ']') ? get_array_value (tok, 0, (int *)NULL) : get_variable_value (v);
value = (e == ']') ? get_array_value (tok, 0, (int *)NULL, &ind) : get_variable_value (v);
#else
value = get_variable_value (v);
#endif
tval = (value && *value) ? subexpr (value) : 0;
if (lvalue)
{
lvalue->tokstr = tok; /* XXX */
lvalue->tokval = tval;
lvalue->tokvar = v; /* XXX */
lvalue->ind = ind;
}
return (tval);
}
@ -1024,6 +1125,7 @@ readtok ()
register char *cp, *xp;
register unsigned char c, c1;
register int e;
struct lvalue lval;
/* Skip leading whitespace. */
cp = tp;
@ -1075,6 +1177,7 @@ readtok ()
tokstr = savestring (tp);
*cp = c;
/* XXX - make peektok part of saved token state? */
SAVETOK (&ec);
tokstr = (char *)NULL; /* keep it from being freed */
tp = savecp = cp;
@ -1090,7 +1193,10 @@ readtok ()
/* The tests for PREINC and PREDEC aren't strictly correct, but they
preserve old behavior if a construct like --x=9 is given. */
if (lasttok == PREINC || lasttok == PREDEC || peektok != EQ)
tokval = expr_streval (tokstr, e);
{
lastlval = curlval;
tokval = expr_streval (tokstr, e, &curlval);
}
else
tokval = 0;

View File

@ -1,7 +1,7 @@
/* externs.h -- extern function declarations which do not appear in their
own header file. */
/* Copyright (C) 1993-2009 Free Software Foundation, Inc.
/* Copyright (C) 1993-2010 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@ -114,7 +114,7 @@ extern int get_current_prompt_level __P((void));
extern void set_current_prompt_level __P((int));
#if defined (HISTORY)
extern char *history_delimiting_chars __P((void));
extern char *history_delimiting_chars __P((const char *));
#endif
/* Declarations for functions defined in locale.c */
@ -178,8 +178,10 @@ extern long get_clk_tck __P((void));
extern void clock_t_to_secs ();
extern void print_clock_t ();
/* Declarations for functions defined in lib/sh/fdprintf.c */
extern void fdprintf __P((int, const char *, ...)) __attribute__((__format__ (printf, 2, 3)));
/* Declarations for functions defined in lib/sh/dprintf.c */
#if !defined (HAVE_DPRINTF)
extern void dprintf __P((int, const char *, ...)) __attribute__((__format__ (printf, 2, 3)));
#endif
/* Declarations for functions defined in lib/sh/fmtulong.c */
#define FL_PREFIX 0x01 /* add 0x, 0X, or 0 prefix as appropriate */
@ -301,9 +303,13 @@ extern int sh_regmatch __P((const char *, const char *, int));
#define SHMAT_SUBEXP 0x001 /* save subexpressions in SH_REMATCH */
#define SHMAT_PWARN 0x002 /* print a warning message on invalid regexp */
/* declarations for functions defined in lib/sh/shmbchar.c */
extern size_t mbstrlen __P((const char *));
extern char *mbsmbchar __P((const char *));
/* declarations for functions defined in lib/sh/shquote.c */
extern char *sh_single_quote __P((char *));
extern char *sh_double_quote __P((char *));
extern char *sh_single_quote __P((const char *));
extern char *sh_double_quote __P((const char *));
extern char *sh_mkdoublequoted __P((const char *, int, int));
extern char *sh_un_double_quote __P((char *));
extern char *sh_backslash_quote __P((char *));
@ -325,6 +331,11 @@ extern int strcasecmp __P((const char *, const char *));
extern char *strcasestr __P((const char *, const char *));
#endif
/* declarations for functions defined in lib/sh/strchrnul.c */
#if ! HAVE_STRCHRNUL
extern char *strchrnul __P((const char *, int));
#endif
/* declarations for functions defined in lib/sh/strerror.c */
#if !defined (HAVE_STRERROR) && !defined (strerror)
extern char *strerror __P((int));
@ -448,6 +459,9 @@ extern int uconvert __P((char *, long *, long *));
extern unsigned int falarm __P((unsigned int, unsigned int));
extern unsigned int fsleep __P((unsigned int, unsigned int));
/* declarations for functions defined in lib/sh/unicode.c */
extern int u32cconv __P((unsigned long, char *));
/* declarations for functions defined in lib/sh/winsize.c */
extern void get_new_window_size __P((int, int *, int *));
@ -472,4 +486,13 @@ extern void zsyncfd __P((int));
/* declarations for functions defined in lib/sh/zwrite.c */
extern int zwrite __P((int, char *, size_t));
/* declarations for functions defined in lib/glob/gmisc.c */
extern int match_pattern_char __P((char *, char *));
extern int umatchlen __P((char *, size_t));
#if defined (HANDLE_MULTIBYTE)
extern int match_pattern_wchar __P((wchar_t *, wchar_t *));
extern int wmatchlen __P((wchar_t *, size_t));
#endif
#endif /* _EXTERNS_H_ */

View File

@ -32,6 +32,7 @@
#if defined (HAVE_UNISTD_H)
# include <unistd.h>
#endif
#include <errno.h>
#include "bashansi.h"
@ -43,6 +44,10 @@
#include "hashcmd.h"
#include "findcmd.h" /* matching prototypes and declarations */
#if !defined (errno)
extern int errno;
#endif
extern int posixly_correct;
/* Static functions defined and used in this file. */
@ -172,6 +177,10 @@ executable_file (file)
int s;
s = file_status (file);
#if defined EISDIR
if (s & FS_DIRECTORY)
errno = EISDIR; /* let's see if we can improve error messages */
#endif
return ((s & FS_EXECABLE) && ((s & FS_DIRECTORY) == 0));
}

View File

@ -363,6 +363,16 @@ sh_validfd (fd)
return (fcntl (fd, F_GETFD, 0) >= 0);
}
int
fd_ispipe (fd)
int fd;
{
errno = 0;
if (lseek ((fd), 0L, SEEK_CUR) < 0)
return (errno == ESPIPE);
return 0;
}
/* There is a bug in the NeXT 2.1 rlogind that causes opens
of /dev/tty to fail. */
@ -549,6 +559,22 @@ file_iswdir (fn)
return (file_isdir (fn) && sh_eaccess (fn, W_OK) == 0);
}
/* Return 1 if STRING is "." or "..", optionally followed by a directory
separator */
int
dot_or_dotdot (string)
const char *string;
{
if (string == 0 || *string == '\0' || *string != '.')
return (0);
/* string[0] == '.' */
if (PATHSEP(string[1]) || (string[1] == '.' && PATHSEP(string[2])))
return (1);
return (0);
}
/* Return 1 if STRING contains an absolute pathname, else 0. Used by `cd'
to decide whether or not to look up a directory name in $CDPATH. */
int

View File

@ -216,8 +216,8 @@ typedef void sh_resetsig_func_t __P((int)); /* sh_vintfunc_t */
typedef int sh_ignore_func_t __P((const char *)); /* sh_icpfunc_t */
typedef int sh_assign_func_t __P((const char *)); /* sh_icpfunc_t */
typedef int sh_wassign_func_t __P((WORD_DESC *));
typedef int sh_assign_func_t __P((const char *));
typedef int sh_wassign_func_t __P((WORD_DESC *, int));
typedef int sh_builtin_func_t __P((WORD_LIST *)); /* sh_wlist_func_t */
@ -289,6 +289,7 @@ extern int assignment __P((const char *, int));
extern int sh_unset_nodelay_mode __P((int));
extern int sh_validfd __P((int));
extern int fd_ispipe __P((int));
extern void check_dev_tty __P((void));
extern int move_to_high_fd __P((int, int, int));
extern int check_binary_file __P((char *, int));
@ -303,6 +304,7 @@ extern int sh_closepipe __P((int *));
extern int file_exists __P((char *));
extern int file_isdir __P((char *));
extern int file_iswdir __P((char *));
extern int dot_or_dotdot __P((const char *));
extern int absolute_pathname __P((const char *));
extern int absolute_program __P((const char *));

View File

@ -107,7 +107,7 @@
#endif
#ifndef UNCTRL
/* control char to letter -- ASCII */
# define UNCTRL(x) (TOUPPER((x) | 0x40))
# define UNCTRL(x) (TOUPPER(x) ^ 0x40)
#endif
#endif /* _SH_CHARTYPES_H */

View File

@ -42,4 +42,12 @@
# endif
#endif
/* Make sure O_BINARY and O_TEXT are defined to avoid Windows-specific code. */
#if !defined (O_BINARY)
# define O_BINARY 0
#endif
#if !defined (O_TEXT)
# define O_TEXT 0
#endif
#endif /* ! _FILECNTL_H_ */

47
include/posixselect.h Normal file
View File

@ -0,0 +1,47 @@
/* posixselect.h -- wrapper for select(2) includes and definitions */
/* Copyright (C) 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/>.
*/
#ifndef _POSIXSELECT_H_
#define _POSIXSELECT_H_
#if defined (FD_SET) && !defined (HAVE_SELECT)
# define HAVE_SELECT 1
#endif
#if defined (HAVE_SELECT)
# if !defined (HAVE_SYS_SELECT_H) || !defined (M_UNIX)
# include <sys/time.h>
# endif
#endif /* HAVE_SELECT */
#if defined (HAVE_SYS_SELECT_H)
# include <sys/select.h>
#endif
#ifndef USEC_PER_SEC
# define USEC_PER_SEC 1000000
#endif
#define USEC_TO_TIMEVAL(us, tv) \
do { \
(tv).tv_sec = (us) / USEC_PER_SEC; \
(tv).tv_usec = (us) % USEC_PER_SEC; \
} while (0)
#endif /* _POSIXSELECT_H_ */

353
include/shmbchar.h Normal file
View File

@ -0,0 +1,353 @@
/* Multibyte character data type.
Copyright (C) 2001, 2005-2007, 2009-2010 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 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.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* Written by Bruno Haible <bruno@clisp.org>. */
/* A multibyte character is a short subsequence of a char* string,
representing a single wide character.
We use multibyte characters instead of wide characters because of
the following goals:
1) correct multibyte handling, i.e. operate according to the LC_CTYPE
locale,
2) ease of maintenance, i.e. the maintainer needs not know all details
of the ISO C 99 standard,
3) don't fail grossly if the input is not in the encoding set by the
locale, because often different encodings are in use in the same
countries (ISO-8859-1/UTF-8, EUC-JP/Shift_JIS, ...),
4) fast in the case of ASCII characters,
5) portability, i.e. don't make unportable assumptions about wchar_t.
Multibyte characters are only accessed through the mb* macros.
mb_ptr (mbc)
return a pointer to the beginning of the multibyte sequence.
mb_len (mbc)
returns the number of bytes occupied by the multibyte sequence.
Always > 0.
mb_iseq (mbc, sc)
returns true if mbc is the standard ASCII character sc.
mb_isnul (mbc)
returns true if mbc is the nul character.
mb_cmp (mbc1, mbc2)
returns a positive, zero, or negative value depending on whether mbc1
sorts after, same or before mbc2.
mb_casecmp (mbc1, mbc2)
returns a positive, zero, or negative value depending on whether mbc1
sorts after, same or before mbc2, modulo upper/lowercase conversion.
mb_equal (mbc1, mbc2)
returns true if mbc1 and mbc2 are equal.
mb_caseequal (mbc1, mbc2)
returns true if mbc1 and mbc2 are equal modulo upper/lowercase conversion.
mb_isalnum (mbc)
returns true if mbc is alphanumeric.
mb_isalpha (mbc)
returns true if mbc is alphabetic.
mb_isascii(mbc)
returns true if mbc is plain ASCII.
mb_isblank (mbc)
returns true if mbc is a blank.
mb_iscntrl (mbc)
returns true if mbc is a control character.
mb_isdigit (mbc)
returns true if mbc is a decimal digit.
mb_isgraph (mbc)
returns true if mbc is a graphic character.
mb_islower (mbc)
returns true if mbc is lowercase.
mb_isprint (mbc)
returns true if mbc is a printable character.
mb_ispunct (mbc)
returns true if mbc is a punctuation character.
mb_isspace (mbc)
returns true if mbc is a space character.
mb_isupper (mbc)
returns true if mbc is uppercase.
mb_isxdigit (mbc)
returns true if mbc is a hexadecimal digit.
mb_width (mbc)
returns the number of columns on the output device occupied by mbc.
Always >= 0.
mb_putc (mbc, stream)
outputs mbc on stream, a byte oriented FILE stream opened for output.
mb_setascii (&mbc, sc)
assigns the standard ASCII character sc to mbc.
mb_copy (&destmbc, &srcmbc)
copies srcmbc to destmbc.
Here are the function prototypes of the macros.
typedef int bool;
extern const char * mb_ptr (const mbchar_t mbc);
extern size_t mb_len (const mbchar_t mbc);
extern bool mb_iseq (const mbchar_t mbc, char sc);
extern bool mb_isnul (const mbchar_t mbc);
extern int mb_cmp (const mbchar_t mbc1, const mbchar_t mbc2);
extern int mb_casecmp (const mbchar_t mbc1, const mbchar_t mbc2);
extern bool mb_equal (const mbchar_t mbc1, const mbchar_t mbc2);
extern bool mb_caseequal (const mbchar_t mbc1, const mbchar_t mbc2);
extern bool mb_isalnum (const mbchar_t mbc);
extern bool mb_isalpha (const mbchar_t mbc);
extern bool mb_isascii (const mbchar_t mbc);
extern bool mb_isblank (const mbchar_t mbc);
extern bool mb_iscntrl (const mbchar_t mbc);
extern bool mb_isdigit (const mbchar_t mbc);
extern bool mb_isgraph (const mbchar_t mbc);
extern bool mb_islower (const mbchar_t mbc);
extern bool mb_isprint (const mbchar_t mbc);
extern bool mb_ispunct (const mbchar_t mbc);
extern bool mb_isspace (const mbchar_t mbc);
extern bool mb_isupper (const mbchar_t mbc);
extern bool mb_isxdigit (const mbchar_t mbc);
extern int mb_width (const mbchar_t mbc);
extern void mb_putc (const mbchar_t mbc, FILE *stream);
extern void mb_setascii (mbchar_t *new, char sc);
extern void mb_copy (mbchar_t *new, const mbchar_t *old);
*/
#ifndef _SHMBCHAR_H
#define _SHMBCHAR_H 1
#if defined (HANDLE_MULTIBYTE)
#include <string.h>
/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
<wchar.h>.
BSD/OS 4.1 has a bug: <stdio.h> and <time.h> must be included before
<wchar.h>. */
#include <stdio.h>
#include <time.h>
#include <wchar.h>
#include <wctype.h>
#define MBCHAR_BUF_SIZE 24
struct mbchar
{
const char *ptr; /* pointer to current character */
size_t bytes; /* number of bytes of current character, > 0 */
int wc_valid; /* true if wc is a valid wide character */
wchar_t wc; /* if wc_valid: the current character */
char buf[MBCHAR_BUF_SIZE]; /* room for the bytes, used for file input only */
};
/* EOF (not a real character) is represented with bytes = 0 and
wc_valid = false. */
typedef struct mbchar mbchar_t;
/* Access the current character. */
#define mb_ptr(mbc) ((mbc).ptr)
#define mb_len(mbc) ((mbc).bytes)
/* Comparison of characters. */
#define mb_iseq(mbc, sc) ((mbc).wc_valid && (mbc).wc == (sc))
#define mb_isnul(mbc) ((mbc).wc_valid && (mbc).wc == 0)
#define mb_cmp(mbc1, mbc2) \
((mbc1).wc_valid \
? ((mbc2).wc_valid \
? (int) (mbc1).wc - (int) (mbc2).wc \
: -1) \
: ((mbc2).wc_valid \
? 1 \
: (mbc1).bytes == (mbc2).bytes \
? memcmp ((mbc1).ptr, (mbc2).ptr, (mbc1).bytes) \
: (mbc1).bytes < (mbc2).bytes \
? (memcmp ((mbc1).ptr, (mbc2).ptr, (mbc1).bytes) > 0 ? 1 : -1) \
: (memcmp ((mbc1).ptr, (mbc2).ptr, (mbc2).bytes) >= 0 ? 1 : -1)))
#define mb_casecmp(mbc1, mbc2) \
((mbc1).wc_valid \
? ((mbc2).wc_valid \
? (int) towlower ((mbc1).wc) - (int) towlower ((mbc2).wc) \
: -1) \
: ((mbc2).wc_valid \
? 1 \
: (mbc1).bytes == (mbc2).bytes \
? memcmp ((mbc1).ptr, (mbc2).ptr, (mbc1).bytes) \
: (mbc1).bytes < (mbc2).bytes \
? (memcmp ((mbc1).ptr, (mbc2).ptr, (mbc1).bytes) > 0 ? 1 : -1) \
: (memcmp ((mbc1).ptr, (mbc2).ptr, (mbc2).bytes) >= 0 ? 1 : -1)))
#define mb_equal(mbc1, mbc2) \
((mbc1).wc_valid && (mbc2).wc_valid \
? (mbc1).wc == (mbc2).wc \
: (mbc1).bytes == (mbc2).bytes \
&& memcmp ((mbc1).ptr, (mbc2).ptr, (mbc1).bytes) == 0)
#define mb_caseequal(mbc1, mbc2) \
((mbc1).wc_valid && (mbc2).wc_valid \
? towlower ((mbc1).wc) == towlower ((mbc2).wc) \
: (mbc1).bytes == (mbc2).bytes \
&& memcmp ((mbc1).ptr, (mbc2).ptr, (mbc1).bytes) == 0)
/* <ctype.h>, <wctype.h> classification. */
#define mb_isascii(mbc) \
((mbc).wc_valid && (mbc).wc >= 0 && (mbc).wc <= 127)
#define mb_isalnum(mbc) ((mbc).wc_valid && iswalnum ((mbc).wc))
#define mb_isalpha(mbc) ((mbc).wc_valid && iswalpha ((mbc).wc))
#define mb_isblank(mbc) ((mbc).wc_valid && iswblank ((mbc).wc))
#define mb_iscntrl(mbc) ((mbc).wc_valid && iswcntrl ((mbc).wc))
#define mb_isdigit(mbc) ((mbc).wc_valid && iswdigit ((mbc).wc))
#define mb_isgraph(mbc) ((mbc).wc_valid && iswgraph ((mbc).wc))
#define mb_islower(mbc) ((mbc).wc_valid && iswlower ((mbc).wc))
#define mb_isprint(mbc) ((mbc).wc_valid && iswprint ((mbc).wc))
#define mb_ispunct(mbc) ((mbc).wc_valid && iswpunct ((mbc).wc))
#define mb_isspace(mbc) ((mbc).wc_valid && iswspace ((mbc).wc))
#define mb_isupper(mbc) ((mbc).wc_valid && iswupper ((mbc).wc))
#define mb_isxdigit(mbc) ((mbc).wc_valid && iswxdigit ((mbc).wc))
/* Extra <wchar.h> function. */
/* Unprintable characters appear as a small box of width 1. */
#define MB_UNPRINTABLE_WIDTH 1
static inline int
mb_width_aux (wint_t wc)
{
int w = wcwidth (wc);
/* For unprintable characters, arbitrarily return 0 for control characters
and MB_UNPRINTABLE_WIDTH otherwise. */
return (w >= 0 ? w : iswcntrl (wc) ? 0 : MB_UNPRINTABLE_WIDTH);
}
#define mb_width(mbc) \
((mbc).wc_valid ? mb_width_aux ((mbc).wc) : MB_UNPRINTABLE_WIDTH)
/* Output. */
#define mb_putc(mbc, stream) fwrite ((mbc).ptr, 1, (mbc).bytes, (stream))
/* Assignment. */
#define mb_setascii(mbc, sc) \
((mbc)->ptr = (mbc)->buf, (mbc)->bytes = 1, (mbc)->wc_valid = 1, \
(mbc)->wc = (mbc)->buf[0] = (sc))
/* Copying a character. */
static inline void
mb_copy (mbchar_t *new_mbc, const mbchar_t *old_mbc)
{
if (old_mbc->ptr == &old_mbc->buf[0])
{
memcpy (&new_mbc->buf[0], &old_mbc->buf[0], old_mbc->bytes);
new_mbc->ptr = &new_mbc->buf[0];
}
else
new_mbc->ptr = old_mbc->ptr;
new_mbc->bytes = old_mbc->bytes;
if ((new_mbc->wc_valid = old_mbc->wc_valid))
new_mbc->wc = old_mbc->wc;
}
/* is_basic(c) tests whether the single-byte character c is in the
ISO C "basic character set".
This is a convenience function, and is in this file only to share code
between mbiter_multi.h and mbfile_multi.h. */
#if (' ' == 32) && ('!' == 33) && ('"' == 34) && ('#' == 35) \
&& ('%' == 37) && ('&' == 38) && ('\'' == 39) && ('(' == 40) \
&& (')' == 41) && ('*' == 42) && ('+' == 43) && (',' == 44) \
&& ('-' == 45) && ('.' == 46) && ('/' == 47) && ('0' == 48) \
&& ('1' == 49) && ('2' == 50) && ('3' == 51) && ('4' == 52) \
&& ('5' == 53) && ('6' == 54) && ('7' == 55) && ('8' == 56) \
&& ('9' == 57) && (':' == 58) && (';' == 59) && ('<' == 60) \
&& ('=' == 61) && ('>' == 62) && ('?' == 63) && ('A' == 65) \
&& ('B' == 66) && ('C' == 67) && ('D' == 68) && ('E' == 69) \
&& ('F' == 70) && ('G' == 71) && ('H' == 72) && ('I' == 73) \
&& ('J' == 74) && ('K' == 75) && ('L' == 76) && ('M' == 77) \
&& ('N' == 78) && ('O' == 79) && ('P' == 80) && ('Q' == 81) \
&& ('R' == 82) && ('S' == 83) && ('T' == 84) && ('U' == 85) \
&& ('V' == 86) && ('W' == 87) && ('X' == 88) && ('Y' == 89) \
&& ('Z' == 90) && ('[' == 91) && ('\\' == 92) && (']' == 93) \
&& ('^' == 94) && ('_' == 95) && ('a' == 97) && ('b' == 98) \
&& ('c' == 99) && ('d' == 100) && ('e' == 101) && ('f' == 102) \
&& ('g' == 103) && ('h' == 104) && ('i' == 105) && ('j' == 106) \
&& ('k' == 107) && ('l' == 108) && ('m' == 109) && ('n' == 110) \
&& ('o' == 111) && ('p' == 112) && ('q' == 113) && ('r' == 114) \
&& ('s' == 115) && ('t' == 116) && ('u' == 117) && ('v' == 118) \
&& ('w' == 119) && ('x' == 120) && ('y' == 121) && ('z' == 122) \
&& ('{' == 123) && ('|' == 124) && ('}' == 125) && ('~' == 126)
/* The character set is ISO-646, not EBCDIC. */
# define IS_BASIC_ASCII 1
extern const unsigned int is_basic_table[];
static inline int
is_basic (char c)
{
return (is_basic_table [(unsigned char) c >> 5] >> ((unsigned char) c & 31))
& 1;
}
#else
static inline int
is_basic (char c)
{
switch (c)
{
case '\t': case '\v': case '\f':
case ' ': case '!': case '"': case '#': case '%':
case '&': case '\'': case '(': case ')': case '*':
case '+': case ',': case '-': case '.': case '/':
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
case ':': case ';': case '<': case '=': case '>':
case '?':
case 'A': case 'B': case 'C': case 'D': case 'E':
case 'F': case 'G': case 'H': case 'I': case 'J':
case 'K': case 'L': case 'M': case 'N': case 'O':
case 'P': case 'Q': case 'R': case 'S': case 'T':
case 'U': case 'V': case 'W': case 'X': case 'Y':
case 'Z':
case '[': case '\\': case ']': case '^': case '_':
case 'a': case 'b': case 'c': case 'd': case 'e':
case 'f': case 'g': case 'h': case 'i': case 'j':
case 'k': case 'l': case 'm': case 'n': case 'o':
case 'p': case 'q': case 'r': case 's': case 't':
case 'u': case 'v': case 'w': case 'x': case 'y':
case 'z': case '{': case '|': case '}': case '~':
return 1;
default:
return 0;
}
}
#endif
#endif /* HANDLE_MULTIBYTE */
#endif /* _SHMBCHAR_H */

View File

@ -27,6 +27,7 @@
#include <config.h>
#if defined (HANDLE_MULTIBYTE)
#include "shmbchar.h"
extern size_t xmbsrtowcs __P((wchar_t *, const char **, size_t, mbstate_t *));
extern size_t xdupmbstowcs __P((wchar_t **, char ***, const char *));
@ -101,9 +102,16 @@ extern char *xstrchr __P((const char *, int));
{ \
mbstate_t state_bak; \
size_t mblength; \
int _f; \
\
state_bak = state; \
mblength = mbrlen ((_str) + (_i), (_strsize) - (_i), &state); \
_f = is_basic ((_str)[_i]); \
if (_f) \
mblength = 1; \
else \
{ \
state_bak = state; \
mblength = mbrlen ((_str) + (_i), (_strsize) - (_i), &state); \
} \
\
if (mblength == (size_t)-2 || mblength == (size_t)-1) \
{ \
@ -134,9 +142,16 @@ extern char *xstrchr __P((const char *, int));
{ \
mbstate_t state_bak; \
size_t mblength; \
int _f; \
\
state_bak = state; \
mblength = mbrlen ((_str), (_strsize), &state); \
_f = is_basic (*(_str)); \
if (_f) \
mblength = 1; \
else \
{ \
state_bak = state; \
mblength = mbrlen ((_str), (_strsize), &state); \
} \
\
if (mblength == (size_t)-2 || mblength == (size_t)-1) \
{ \
@ -247,8 +262,14 @@ extern char *xstrchr __P((const char *, int));
size_t mblength; \
int _k; \
\
state_bak = state; \
mblength = mbrlen ((_src), (_srcend) - (_src), &state); \
_k = is_basic (*(_src)); \
if (_k) \
mblength = 1; \
else \
{ \
state_bak = state; \
mblength = mbrlen ((_src), (_srcend) - (_src), &state); \
} \
if (mblength == (size_t)-2 || mblength == (size_t)-1) \
{ \
state = state_bak; \
@ -280,8 +301,14 @@ extern char *xstrchr __P((const char *, int));
size_t mblength; \
int _k; \
\
state_bak = state; \
mblength = mbrlen ((_src) + (_si), (_srcend) - ((_src)+(_si)), &state); \
_k = is_basic (*((_src) + (_si))); \
if (_k) \
mblength = 1; \
else \
{\
state_bak = state; \
mblength = mbrlen ((_src) + (_si), (_srcend) - ((_src)+(_si)), &state); \
} \
if (mblength == (size_t)-2 || mblength == (size_t)-1) \
{ \
state = state_bak; \
@ -317,8 +344,14 @@ extern char *xstrchr __P((const char *, int));
size_t mblength; \
int _i; \
\
state_bak = state; \
mblength = mbrlen ((_src) + (_si), (_slen) - (_si), &state); \
_i = is_basic (*((_src) + (_si))); \
if (_i) \
mblength = 1; \
else \
{ \
state_bak = state; \
mblength = mbrlen ((_src) + (_si), (_slen) - (_si), &state); \
} \
if (mblength == (size_t)-2 || mblength == (size_t)-1) \
{ \
state = state_bak; \
@ -356,9 +389,16 @@ extern char *xstrchr __P((const char *, int));
{ \
mbstate_t state_bak; \
size_t mblength; \
int _i; \
\
state_bak = state; \
mblength = mbrlen ((_src) + (_si), (_srcend) - ((_src) + (_si)), &state); \
_i = is_basic (*((_src) + (_si))); \
if (_i) \
mblength = 1; \
else \
{ \
state_bak = state; \
mblength = mbrlen ((_src) + (_si), (_srcend) - ((_src) + (_si)), &state); \
} \
if (mblength == (size_t)-2 || mblength == (size_t)-1) \
{ \
state = state_bak; \
@ -395,8 +435,14 @@ extern char *xstrchr __P((const char *, int));
mbstate_t state_bak; \
size_t mblength; \
\
state_bak = state; \
mblength = mbrlen ((_src) + (_si), (_srcsize) - (_si), &state); \
i = is_basic (*((_src) + (_si))); \
if (i) \
mblength = 1; \
else \
{ \
state_bak = state; \
mblength = mbrlen ((_src) + (_si), (_srcsize) - (_si), &state); \
} \
if (mblength == (size_t)-1 || mblength == (size_t)-2) \
{ \
state = state_bak; \
@ -427,8 +473,14 @@ extern char *xstrchr __P((const char *, int));
mbstate_t state_bak; \
size_t mblength; \
\
state_bak = state; \
mblength = mbrlen ((_src) + (_si), (_srcsize) - (_si), &state); \
i = is_basic (*((_src) + (_si))); \
if (i) \
mblength = 1; \
else \
{ \
state_bak = state; \
mblength = mbrlen ((_src) + (_si), (_srcsize) - (_si), &state); \
} \
if (mblength == (size_t)-1 || mblength == (size_t)-2) \
{ \
state = state_bak; \

View File

@ -77,6 +77,21 @@ static const unsigned long long int maxquad = ULLONG_MAX;
# define ULLONG_MAX maxquad
#endif
#if !defined (INTMAX_MAX) || !defined (INTMAX_MIN)
#if SIZEOF_INTMAX_T == SIZEOF_LONG_LONG
# define INTMAX_MAX LLONG_MAX
# define INTMAX_MIN LLONG_MIN
#elif SIZEOF_INTMAX_T == SIZEOF_LONG
# define INTMAX_MAX LONG_MAX
# define INTMAX_MIN LONG_MIN
#else
# define INTMAX_MAX INT_MAX
# define INTMAX_MIN INT_MIN
#endif
#endif
#ifndef SSIZE_MAX
# define SSIZE_MAX 32767 /* POSIX minimum max */
#endif

37
input.c
View File

@ -193,6 +193,8 @@ make_buffered_stream (fd, buffer, bufsize)
bp->b_used = bp->b_inputp = bp->b_flag = 0;
if (bufsize == 1)
bp->b_flag |= B_UNBUFF;
if (O_TEXT && (fcntl (fd, F_GETFL) & O_TEXT) != 0)
bp->b_flag |= O_TEXT;
return (bp);
}
@ -361,11 +363,7 @@ duplicate_buffered_stream (fd1, fd2)
}
/* Return 1 if a seek on FD will succeed. */
#ifndef __CYGWIN__
# define fd_is_seekable(fd) (lseek ((fd), 0L, SEEK_CUR) >= 0)
#else
# define fd_is_seekable(fd) 0
#endif /* __CYGWIN__ */
#define fd_is_seekable(fd) (lseek ((fd), 0L, SEEK_CUR) >= 0)
/* Take FD, a file descriptor, and create and return a buffered stream
corresponding to it. If something is wrong and the file descriptor
@ -472,9 +470,27 @@ b_fill_buffer (bp)
BUFFERED_STREAM *bp;
{
ssize_t nr;
off_t o;
CHECK_TERMSIG;
nr = zread (bp->b_fd, bp->b_buffer, bp->b_size);
/* In an environment where text and binary files are treated differently,
compensate for lseek() on text files returning an offset different from
the count of characters read() returns. Text-mode streams have to be
treated as unbuffered. */
if ((bp->b_flag & (B_TEXT | B_UNBUFF)) == B_TEXT)
{
o = lseek (bp->b_fd, 0, SEEK_CUR);
nr = zread (bp->b_fd, bp->b_buffer, bp->b_size);
if (nr > 0 && nr < lseek (bp->b_fd, 0, SEEK_CUR) - o)
{
lseek (bp->b_fd, o, SEEK_SET);
bp->b_flag |= B_UNBUFF;
bp->b_size = 1;
nr = zread (bp->b_fd, bp->b_buffer, bp->b_size);
}
}
else
nr = zread (bp->b_fd, bp->b_buffer, bp->b_size);
if (nr <= 0)
{
bp->b_used = 0;
@ -486,15 +502,6 @@ b_fill_buffer (bp)
return (EOF);
}
#if defined (__CYGWIN__)
/* If on cygwin, translate \r\n to \n. */
if (nr >= 2 && bp->b_buffer[nr - 2] == '\r' && bp->b_buffer[nr - 1] == '\n')
{
bp->b_buffer[nr - 2] = '\n';
nr--;
}
#endif
bp->b_used = nr;
bp->b_inputp = 0;
return (bp->b_buffer[bp->b_inputp++] & 0xFF);

View File

@ -48,6 +48,7 @@ enum stream_type {st_none, st_stdin, st_stream, st_string, st_bstream};
#define B_ERROR 0x02
#define B_UNBUFF 0x04
#define B_WASBASHINPUT 0x08
#define B_TEXT 0x10
/* A buffered stream. Like a FILE *, but with our own buffering and
synchronization. Look in input.c for the implementation. */

64
jobs.c
View File

@ -3,7 +3,7 @@
/* This file works with both POSIX and BSD systems. It implements job
control. */
/* Copyright (C) 1989-2009 Free Software Foundation, Inc.
/* Copyright (C) 1989-2010 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@ -77,6 +77,10 @@
extern int errno;
#endif /* !errno */
#if !defined (HAVE_KILLPG)
extern int killpg __P((pid_t, int));
#endif
#define DEFAULT_CHILD_MAX 32
#if !defined (DEBUG)
#define MAX_JOBS_IN_ARRAY 4096 /* production */
@ -246,8 +250,6 @@ static int find_job __P((pid_t, int, PROCESS **));
static int print_job __P((JOB *, int, int, int));
static int process_exit_status __P((WAIT));
static int process_exit_signal __P((WAIT));
static int job_exit_status __P((int));
static int job_exit_signal __P((int));
static int set_job_status_and_cleanup __P((int));
static WAIT job_signal_status __P((int));
@ -645,7 +647,7 @@ stop_pipeline (async, deferred)
stop_making_children ();
UNBLOCK_CHILD (oset);
return (js.j_current);
return (newjob ? i : js.j_current);
}
/* Functions to manage the list of exited background pids whose status has
@ -1134,6 +1136,33 @@ add_process (name, pid)
}
}
/* Create a (dummy) PROCESS with NAME, PID, and STATUS, and make it the last
process in jobs[JID]->pipe. Used by the lastpipe code. */
void
append_process (name, pid, status, jid)
char *name;
pid_t pid;
int status;
int jid;
{
PROCESS *t, *p;
t = (PROCESS *)xmalloc (sizeof (PROCESS));
t->next = (PROCESS *)NULL;
t->pid = pid;
/* set process exit status using offset discovered by configure */
t->status = (status & 0xff) << WEXITSTATUS_OFFSET;
t->running = PS_DONE;
t->command = name;
js.c_reaped++; /* XXX */
for (p = jobs[jid]->pipe; p->next != jobs[jid]->pipe; p = p->next)
;
p->next = t;
t->next = jobs[jid]->pipe;
}
#if 0
/* Take the last job and make it the first job. Must be called with
SIGCHLD blocked. */
@ -1708,10 +1737,10 @@ make_child (command, async_p)
/* Create the child, handle severe errors. Retry on EAGAIN. */
while ((pid = fork ()) < 0 && errno == EAGAIN && forksleep < FORKSLEEP_MAX)
{
#if 0 /* for bash-4.2 */
/* bash-4.2 */
/* If we can't create any children, try to reap some dead ones. */
waitchld (-1, 0);
#endif
sys_error ("fork: retry");
if (sleep (forksleep) != 0)
break;
@ -2125,7 +2154,7 @@ wait_for_single_pid (pid)
return r;
}
/* Wait for all of the backgrounds of this shell to finish. */
/* Wait for all of the background processes started by this shell to finish. */
void
wait_for_background_pids ()
{
@ -2306,14 +2335,14 @@ raw_job_exit_status (job)
/* Return the exit status of job JOB. This is the exit status of the last
(rightmost) process in the job's pipeline, modified if the job was killed
by a signal or stopped. */
static int
int
job_exit_status (job)
int job;
{
return (process_exit_status (raw_job_exit_status (job)));
}
static int
int
job_exit_signal (job)
int job;
{
@ -2347,7 +2376,6 @@ wait_for (pid)
WAIT s;
register PROCESS *child;
sigset_t set, oset;
register PROCESS *p;
/* In the case that this code is interrupted, and we longjmp () out of it,
we are relying on the code in throw_to_top_level () to restore the
@ -2549,11 +2577,13 @@ if (job == NO_JOB)
}
}
}
else if ((subshell_environment & SUBSHELL_COMSUB) && wait_sigint_received)
else if ((subshell_environment & (SUBSHELL_COMSUB|SUBSHELL_PIPE)) && wait_sigint_received)
{
/* If waiting for a job in a subshell started to do command
substitution, simulate getting and being killed by the SIGINT to
pass the status back to our parent. */
substitution or to run a pipeline element that consists of
something like a while loop or a for loop, simulate getting
and being killed by the SIGINT to pass the status back to our
parent. */
s = job_signal_status (job);
if (WIFSIGNALED (s) && WTERMSIG (s) == SIGINT && signal_is_trapped (SIGINT) == 0)
@ -4114,7 +4144,13 @@ itrace("mark_dead_jobs_as_notified: child_max = %d ndead = %d ndeadproc = %d", j
}
/* Here to allow other parts of the shell (like the trap stuff) to
unfreeze the jobs list. */
freeze and unfreeze the jobs list. */
void
freeze_jobs_list ()
{
jobs_list_frozen = 1;
}
void
unfreeze_jobs_list ()
{

5
jobs.h
View File

@ -177,6 +177,7 @@ extern void save_pipeline __P((int));
extern void restore_pipeline __P((int));
extern void start_pipeline __P((void));
extern int stop_pipeline __P((int, COMMAND *));
extern void append_process __P((char *, pid_t, int, int));
extern void delete_job __P((int, int));
extern void nohup_job __P((int));
@ -208,6 +209,9 @@ extern pid_t make_child __P((char *, int));
extern int get_tty_state __P((void));
extern int set_tty_state __P((void));
extern int job_exit_status __P((int));
extern int job_exit_signal __P((int));
extern int wait_for_single_pid __P((pid_t));
extern void wait_for_background_pids __P((void));
extern int wait_for __P((pid_t));
@ -223,6 +227,7 @@ extern int give_terminal_to __P((pid_t, int));
extern void run_sigchld_trap __P((int));
extern void freeze_jobs_list __P((void));
extern void unfreeze_jobs_list __P((void));
extern int set_job_control __P((int));
extern void without_job_control __P((void));

View File

@ -71,7 +71,7 @@ CSOURCES = $(srcdir)/glob.c $(srcdir)/strmatch.c $(srcdir)/smatch.c \
# The header files for this library.
HSOURCES = $(srcdir)/strmatch.h
OBJECTS = glob.o strmatch.o smatch.o xmbsrtowcs.o
OBJECTS = glob.o strmatch.o smatch.o xmbsrtowcs.o gmisc.o
# The texinfo files which document this library.
DOCSOURCE = doc/glob.texi
@ -119,6 +119,9 @@ realclean distclean maintainer-clean: clean
mostlyclean: clean
-( cd doc && $(MAKE) $(MFLAGS) $@ )
${BUILD_DIR}/pathnames.h: ${BUILD_DIR}/config.h ${BUILD_DIR}/Makefile Makefile
-( cd ${BUILD_DIR} && ${MAKE} ${MFLAGS} pathnames.h )
######################################################################
# #
# Dependencies for the object files which make up this library. #
@ -137,18 +140,24 @@ strmatch.o: $(BUILD_DIR)/config.h
strmatch.o: $(BASHINCDIR)/stdc.h
glob.o: $(BUILD_DIR)/config.h
glob.o: $(topdir)/shell.h $(BUILD_DIR)/pathnames.h
glob.o: $(topdir)/bashtypes.h $(BASHINCDIR)/ansi_stdlib.h $(topdir)/bashansi.h
glob.o: $(BASHINCDIR)/posixstat.h $(BASHINCDIR)/memalloc.h
glob.o: strmatch.h glob.h
glob.o: $(BASHINCDIR)/shmbutil.h
glob.o: $(topdir)/xmalloc.h
gmisc.o: $(BUILD_DIR)/config.h
gmisc.o: $(topdir)/bashtypes.h $(BASHINCDIR)/ansi_stdlib.h $(topdir)/bashansi.h
gmisc.o: $(BASHINCDIR)/shmbutil.h
xmbsrtowcs.o: ${BUILD_DIR}/config.h
xmbsrtowcs.o: ${topdir}/bashansi.h ${BASHINCDIR}/ansi_stdlib.h
xmbsrtowcs.o: ${BASHINCDIR}/shmbutil.h
# Rules for deficient makes, like SunOS and Solaris
glob.o: glob.c
gmisc.o: gmisc.c
strmatch.o: strmatch.c
smatch.o: smatch.c
xmbsrtowcs.o: xmbsrtowcs.c

314
lib/glob/gmisc.c Normal file
View File

@ -0,0 +1,314 @@
/* gmisc.c -- miscellaneous pattern matching utility functions for Bash.
Copyright (C) 2010 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne-Again SHell.
Bash is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Bash is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Bash. If not, see <http://www.gnu.org/licenses/>.
*/
#include <config.h>
#include "bashtypes.h"
#if defined (HAVE_UNISTD_H)
# include <unistd.h>
#endif
#include "bashansi.h"
#include "shmbutil.h"
#include "stdc.h"
#ifndef LPAREN
# define LPAREN '('
#endif
#ifndef RPAREN
# define RPAREN ')'
#endif
#if defined (HANDLE_MULTIBYTE)
#define WLPAREN L'('
#define WRPAREN L')'
/* Return 1 of the first character of WSTRING could match the first
character of pattern WPAT. Wide character version. */
int
match_pattern_wchar (wpat, wstring)
wchar_t *wpat, *wstring;
{
wchar_t wc;
if (*wstring == 0)
return (0);
switch (wc = *wpat++)
{
default:
return (*wstring == wc);
case L'\\':
return (*wstring == *wpat);
case L'?':
return (*wpat == WLPAREN ? 1 : (*wstring != L'\0'));
case L'*':
return (1);
case L'+':
case L'!':
case L'@':
return (*wpat == WLPAREN ? 1 : (*wstring == wc));
case L'[':
return (*wstring != L'\0');
}
}
int
wmatchlen (wpat, wmax)
wchar_t *wpat;
size_t wmax;
{
wchar_t wc, *wbrack;
int matlen, t, in_cclass, in_collsym, in_equiv;
if (*wpat == 0)
return (0);
matlen = in_cclass = in_collsym = in_equiv = 0;
while (wc = *wpat++)
{
switch (wc)
{
default:
matlen++;
break;
case L'\\':
if (*wpat == 0)
return ++matlen;
else
{
matlen++;
wpat++;
}
break;
case L'?':
if (*wpat == WLPAREN)
return (matlen = -1); /* XXX for now */
else
matlen++;
break;
case L'*':
return (matlen = -1);
case L'+':
case L'!':
case L'@':
if (*wpat == WLPAREN)
return (matlen = -1); /* XXX for now */
else
matlen++;
break;
case L'[':
/* scan for ending `]', skipping over embedded [:...:] */
wbrack = wpat;
wc = *wpat++;
do
{
if (wc == 0)
{
matlen += wpat - wbrack - 1; /* incremented below */
break;
}
else if (wc == L'\\')
{
wc = *wpat++;
if (*wpat == 0)
break;
}
else if (wc == L'[' && *wpat == L':') /* character class */
{
wpat++;
in_cclass = 1;
}
else if (in_cclass && wc == L':' && *wpat == L']')
{
wpat++;
in_cclass = 0;
}
else if (wc == L'[' && *wpat == L'.') /* collating symbol */
{
wpat++;
if (*wpat == L']') /* right bracket can appear as collating symbol */
wpat++;
in_collsym = 1;
}
else if (in_collsym && wc == L'.' && *wpat == L']')
{
wpat++;
in_collsym = 0;
}
else if (wc == L'[' && *wpat == L'=') /* equivalence class */
{
wpat++;
if (*wpat == L']') /* right bracket can appear as equivalence class */
wpat++;
in_equiv = 1;
}
else if (in_equiv && wc == L'=' && *wpat == L']')
{
wpat++;
in_equiv = 0;
}
}
while ((wc = *wpat++) != L']');
matlen++; /* bracket expression can only match one char */
break;
}
}
return matlen;
}
#endif
/* Return 1 of the first character of STRING could match the first
character of pattern PAT. Used to avoid n2 calls to strmatch(). */
int
match_pattern_char (pat, string)
char *pat, *string;
{
char c;
if (*string == 0)
return (0);
switch (c = *pat++)
{
default:
return (*string == c);
case '\\':
return (*string == *pat);
case '?':
return (*pat == LPAREN ? 1 : (*string != '\0'));
case '*':
return (1);
case '+':
case '!':
case '@':
return (*pat == LPAREN ? 1 : (*string == c));
case '[':
return (*string != '\0');
}
}
int
umatchlen (pat, max)
char *pat;
size_t max;
{
char c, *brack;
int matlen, t, in_cclass, in_collsym, in_equiv;
if (*pat == 0)
return (0);
matlen = in_cclass = in_collsym = in_equiv = 0;
while (c = *pat++)
{
switch (c)
{
default:
matlen++;
break;
case '\\':
if (*pat == 0)
return ++matlen;
else
{
matlen++;
pat++;
}
break;
case '?':
if (*pat == LPAREN)
return (matlen = -1); /* XXX for now */
else
matlen++;
break;
case '*':
return (matlen = -1);
case '+':
case '!':
case '@':
if (*pat == LPAREN)
return (matlen = -1); /* XXX for now */
else
matlen++;
break;
case '[':
/* scan for ending `]', skipping over embedded [:...:] */
brack = pat;
c = *pat++;
do
{
if (c == 0)
{
matlen += pat - brack - 1; /* incremented below */
break;
}
else if (c == '\\')
{
c = *pat++;
if (*pat == 0)
break;
}
else if (c == '[' && *pat == ':') /* character class */
{
pat++;
in_cclass = 1;
}
else if (in_cclass && c == ':' && *pat == ']')
{
pat++;
in_cclass = 0;
}
else if (c == '[' && *pat == '.') /* collating symbol */
{
pat++;
if (*pat == ']') /* right bracket can appear as collating symbol */
pat++;
in_collsym = 1;
}
else if (in_collsym && c == '.' && *pat == ']')
{
pat++;
in_collsym = 0;
}
else if (c == '[' && *pat == '=') /* equivalence class */
{
pat++;
if (*pat == ']') /* right bracket can appear as equivalence class */
pat++;
in_equiv = 1;
}
else if (in_equiv && c == '=' && *pat == ']')
{
pat++;
in_equiv = 0;
}
}
while ((c = *pat++) != ']');
matlen++; /* bracket expression can only match one char */
break;
}
}
return matlen;
}

View File

@ -1,7 +1,7 @@
/* strmatch.c -- ksh-like extended pattern matching for the shell and filename
globbing. */
/* Copyright (C) 1991-2005 Free Software Foundation, Inc.
/* Copyright (C) 1991-2011 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@ -241,6 +241,8 @@ is_cclass (c, name)
# define STREQ(s1, s2) ((wcscmp (s1, s2) == 0))
# define STREQN(a, b, n) ((a)[0] == (b)[0] && wcsncmp(a, b, n) == 0)
extern char *mbsmbchar __P((const char *));
static int
rangecmp_wc (c1, c2)
wint_t c1, c2;
@ -314,7 +316,7 @@ is_wcclass (wc, name)
memset (&state, '\0', sizeof (mbstate_t));
mbs = (char *) malloc (wcslen(name) * MB_CUR_MAX + 1);
mbslength = wcsrtombs(mbs, (const wchar_t **)&name, (wcslen(name) * MB_CUR_MAX + 1), &state);
mbslength = wcsrtombs (mbs, (const wchar_t **)&name, (wcslen(name) * MB_CUR_MAX + 1), &state);
if (mbslength == (size_t)-1 || mbslength == (size_t)-2)
{
@ -365,6 +367,16 @@ xstrmatch (pattern, string, flags)
int ret;
size_t n;
wchar_t *wpattern, *wstring;
size_t plen, slen, mplen, mslen;
#if 0
plen = strlen (pattern);
mplen = mbstrlen (pattern);
if (plen == mplen && strlen (string) == mbstrlen (string))
#else
if (mbsmbchar (string) == 0 && mbsmbchar (pattern) == 0)
#endif
return (internal_strmatch ((unsigned char *)pattern, (unsigned char *)string, flags));
if (MB_CUR_MAX == 1)
return (internal_strmatch ((unsigned char *)pattern, (unsigned char *)string, flags));

View File

@ -1,6 +1,6 @@
/* xmbsrtowcs.c -- replacement function for mbsrtowcs */
/* Copyright (C) 2002-2004 Free Software Foundation, Inc.
/* Copyright (C) 2002-2010 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@ -18,6 +18,12 @@
along with Bash. If not, see <http://www.gnu.org/licenses/>.
*/
/* Ask for GNU extensions to get extern declaration for mbsnrtowcs if
available via glibc. */
#ifndef _GNU_SOURCE
# define _GNU_SOURCE 1
#endif
#include <config.h>
#include <bashansi.h>
@ -32,6 +38,11 @@
#ifndef FREE
# define FREE(x) do { if (x) free (x); } while (0)
#endif
#if ! HAVE_STRCHRNUL
extern char *strchrnul __P((const char *, int));
#endif
/* On some locales (ex. ja_JP.sjis), mbsrtowc doesn't convert 0x5c to U<0x5c>.
So, this function is made for converting 0x5c to U<0x5c>. */
@ -120,6 +131,94 @@ xmbsrtowcs (dest, src, len, pstate)
return (wclength);
}
#if HAVE_MBSNRTOWCS
/* Convert a multibyte string to a wide character string. Memory for the
new wide character string is obtained with malloc.
Fast multiple-character version of xdupmbstowcs used when the indices are
not required and mbsnrtowcs is available. */
static size_t
xdupmbstowcs2 (destp, src)
wchar_t **destp; /* Store the pointer to the wide character string */
const char *src; /* Multibyte character string */
{
const char *p; /* Conversion start position of src */
wchar_t *wsbuf; /* Buffer for wide characters. */
size_t wsbuf_size; /* Size of WSBUF */
size_t wcnum; /* Number of wide characters in WSBUF */
mbstate_t state; /* Conversion State */
size_t wcslength; /* Number of wide characters produced by the conversion. */
const char *end_or_backslash;
size_t nms; /* Number of multibyte characters to convert at one time. */
mbstate_t tmp_state;
const char *tmp_p;
memset (&state, '\0', sizeof(mbstate_t));
wsbuf_size = 0;
wsbuf = NULL;
p = src;
wcnum = 0;
do
{
end_or_backslash = strchrnul(p, '\\');
nms = (end_or_backslash - p);
if (*end_or_backslash == '\0')
nms++;
/* Compute the number of produced wide-characters. */
tmp_p = p;
tmp_state = state;
wcslength = mbsnrtowcs(NULL, &tmp_p, nms, 0, &tmp_state);
/* Conversion failed. */
if (wcslength == (size_t)-1)
{
free (wsbuf);
*destp = NULL;
return (size_t)-1;
}
/* Resize the buffer if it is not large enough. */
if (wsbuf_size < wcnum+wcslength+1) /* 1 for the L'\0' or the potential L'\\' */
{
wchar_t *wstmp;
wsbuf_size = wcnum+wcslength+1; /* 1 for the L'\0' or the potential L'\\' */
wstmp = (wchar_t *) realloc (wsbuf, wsbuf_size * sizeof (wchar_t));
if (wstmp == NULL)
{
free (wsbuf);
*destp = NULL;
return (size_t)-1;
}
wsbuf = wstmp;
}
/* Perform the conversion. This is assumed to return 'wcslength'.
* It may set 'p' to NULL. */
mbsnrtowcs(wsbuf+wcnum, &p, nms, wsbuf_size-wcnum, &state);
wcnum += wcslength;
if (mbsinit (&state) && (p != NULL) && (*p == '\\'))
{
wsbuf[wcnum++] = L'\\';
p++;
}
}
while (p != NULL);
*destp = wsbuf;
/* Return the length of the wide character string, not including `\0'. */
return wcnum;
}
#endif /* HAVE_MBSNRTOWCS */
/* Convert a multibyte string to a wide character string. Memory for the
new wide character string is obtained with malloc.
@ -155,6 +254,11 @@ xdupmbstowcs (destp, indicesp, src)
return (size_t)-1;
}
#if HAVE_MBSNRTOWCS
if (indicesp == NULL)
return (xdupmbstowcs2 (destp, src));
#endif
memset (&state, '\0', sizeof(mbstate_t));
wsbuf_size = WSBUF_INC;

View File

@ -112,6 +112,7 @@ alloca.o: $(BUILD_DIR)/config.h
malloc.o: $(BUILD_DIR)/config.h $(topdir)/bashtypes.h getpagesize.h
xmalloc.o: $(BUILD_DIR)/config.h $(BASHINCDIR)/ansi_stdlib.h
trace.o: ${BUILD_DIR}/config.h
stats.o: ${BUILD_DIR}/config.h
table.o: ${BUILD_DIR}/config.h
watch.o: ${BUILD_DIR}/config.h

View File

@ -83,7 +83,7 @@ CSOURCES = $(srcdir)/readline.c $(srcdir)/funmap.c $(srcdir)/keymaps.c \
$(srcdir)/histfile.c $(srcdir)/nls.c $(srcdir)/search.c \
$(srcdir)/shell.c $(srcdir)/tilde.c $(srcdir)/savestring.c \
$(srcdir)/text.c $(srcdir)/misc.c $(srcdir)/compat.c \
$(srcdir)/mbutil.c
$(srcdir)/mbutil.c $(srcdir)/xfree.c
# The header files for this library.
HSOURCES = readline.h rldefs.h chardefs.h keymaps.h history.h histlib.h \
@ -97,7 +97,7 @@ TILDEOBJ = tilde.o
OBJECTS = readline.o vi_mode.o funmap.o keymaps.o parens.o search.o \
rltty.o complete.o bind.o isearch.o display.o signals.o \
util.o kill.o undo.o macro.o input.o callback.o terminal.o \
text.o nls.o misc.o $(HISTOBJ) $(TILDEOBJ) xmalloc.o compat.o
text.o nls.o misc.o $(HISTOBJ) $(TILDEOBJ) xmalloc.o xfree.o compat.o
# The texinfo files which document this library.
DOCSOURCE = doc/rlman.texinfo doc/rltech.texinfo doc/rluser.texinfo
@ -123,9 +123,9 @@ libreadline.a: $(OBJECTS)
$(AR) $(ARFLAGS) $@ $(OBJECTS)
-test -n "$(RANLIB)" && $(RANLIB) $@
libhistory.a: $(HISTOBJ) xmalloc.o
libhistory.a: $(HISTOBJ) xmalloc.o xfree.o
$(RM) $@
$(AR) $(ARFLAGS) $@ $(HISTOBJ) xmalloc.o
$(AR) $(ARFLAGS) $@ $(HISTOBJ) xmalloc.o xfree.o
-test -n "$(RANLIB)" && $(RANLIB) $@
documentation: force
@ -262,6 +262,7 @@ vi_mode.o: rldefs.h ${BUILD_DIR}/config.h rlconf.h
vi_mode.o: readline.h keymaps.h rltypedefs.h chardefs.h tilde.h
vi_mode.o: history.h ansi_stdlib.h rlstdc.h
xmalloc.o: ${BUILD_DIR}/config.h ansi_stdlib.h
xfree.o: ${BUILD_DIR}/config.h ansi_stdlib.h
bind.o: rlshell.h
histfile.o: rlshell.h
@ -317,6 +318,7 @@ tilde.o: xmalloc.h
undo.o: xmalloc.h
util.o: xmalloc.h
vi_mode.o: xmalloc.h
xfree.o: xmalloc.h
xmalloc.o: xmalloc.h
complete.o: rlmbutil.h
@ -359,6 +361,7 @@ tilde.o: tilde.c
undo.o: undo.c
util.o: util.c
vi_mode.o: vi_mode.c
xfree.o: xfree.c
xmalloc.o: xmalloc.c
histexpand.o: histexpand.c

View File

@ -1,6 +1,6 @@
/* bind.c -- key binding and startup file support for the readline library. */
/* Copyright (C) 1987-2009 Free Software Foundation, Inc.
/* Copyright (C) 1987-2010 Free Software Foundation, Inc.
This file is part of the GNU Readline Library (Readline), a library
for reading lines of text with interactive input and history editing.
@ -1424,6 +1424,7 @@ static const struct {
{ "blink-matching-paren", &rl_blink_matching_paren, V_SPECIAL },
{ "byte-oriented", &rl_byte_oriented, 0 },
{ "completion-ignore-case", &_rl_completion_case_fold, 0 },
{ "completion-map-case", &_rl_completion_case_map, 0 },
{ "convert-meta", &_rl_convert_meta_chars_to_ascii, 0 },
{ "disable-completion", &rl_inhibit_completion, 0 },
{ "echo-control-characters", &_rl_echo_control_chars, 0 },
@ -1437,6 +1438,7 @@ static const struct {
{ "mark-modified-lines", &_rl_mark_modified_lines, 0 },
{ "mark-symlinked-directories", &_rl_complete_mark_symlink_dirs, 0 },
{ "match-hidden-files", &_rl_match_hidden_files, 0 },
{ "menu-complete-display-prefix", &_rl_menu_complete_prefix_first, 0 },
{ "meta-flag", &_rl_meta_flag, 0 },
{ "output-meta", &_rl_output_meta_chars, 0 },
{ "page-completions", &_rl_page_completions, 0 },
@ -1449,7 +1451,7 @@ static const struct {
#if defined (VISIBLE_STATS)
{ "visible-stats", &rl_visible_stats, 0 },
#endif /* VISIBLE_STATS */
{ (char *)NULL, (int *)NULL }
{ (char *)NULL, (int *)NULL, 0 }
};
static int
@ -1504,6 +1506,7 @@ static int sv_bell_style PARAMS((const char *));
static int sv_combegin PARAMS((const char *));
static int sv_dispprefix PARAMS((const char *));
static int sv_compquery PARAMS((const char *));
static int sv_compwidth PARAMS((const char *));
static int sv_editmode PARAMS((const char *));
static int sv_histsize PARAMS((const char *));
static int sv_isrchterm PARAMS((const char *));
@ -1516,13 +1519,14 @@ static const struct {
} string_varlist[] = {
{ "bell-style", V_STRING, sv_bell_style },
{ "comment-begin", V_STRING, sv_combegin },
{ "completion-display-width", V_INT, sv_compwidth },
{ "completion-prefix-display-length", V_INT, sv_dispprefix },
{ "completion-query-items", V_INT, sv_compquery },
{ "editing-mode", V_STRING, sv_editmode },
{ "history-size", V_INT, sv_histsize },
{ "isearch-terminators", V_STRING, sv_isrchterm },
{ "keymap", V_STRING, sv_keymap },
{ (char *)NULL, 0 }
{ (char *)NULL, 0, (_rl_sv_func_t *)0 }
};
static int
@ -1662,6 +1666,19 @@ sv_compquery (value)
return 0;
}
static int
sv_compwidth (value)
const char *value;
{
int nval = -1;
if (value && *value)
nval = atoi (value);
_rl_completion_columns = nval;
return 0;
}
static int
sv_histsize (value)
const char *value;
@ -2268,6 +2285,11 @@ _rl_get_string_variable_value (name)
}
else if (_rl_stricmp (name, "comment-begin") == 0)
return (_rl_comment_begin ? _rl_comment_begin : RL_COMMENT_BEGIN_DEFAULT);
else if (_rl_stricmp (name, "completion-display-width") == 0)
{
sprintf (numbuf, "%d", _rl_completion_columns);
return (numbuf);
}
else if (_rl_stricmp (name, "completion-prefix-display-length") == 0)
{
sprintf (numbuf, "%d", _rl_completion_prefix_display_length);

View File

@ -142,6 +142,15 @@ rl_callback_read_char ()
eof = _rl_nsearch_callback (_rl_nscxt);
return;
}
#if defined (VI_MODE)
else if (RL_ISSTATE (RL_STATE_VIMOTION))
{
eof = _rl_vi_domove_callback (_rl_vimvcxt);
/* Should handle everything, including cleanup, numeric arguments,
and turning off RL_STATE_VIMOTION */
return;
}
#endif
else if (RL_ISSTATE (RL_STATE_NUMERICARG))
{
eof = _rl_arg_callback (_rl_argcxt);

View File

@ -1,6 +1,6 @@
/* complete.c -- filename completion for readline. */
/* Copyright (C) 1987-2009 Free Software Foundation, Inc.
/* Copyright (C) 1987-2011 Free Software Foundation, Inc.
This file is part of the GNU Readline Library (Readline), a library
for reading lines of text with interactive input and history editing.
@ -119,9 +119,11 @@ static char **remove_duplicate_matches PARAMS((char **));
static void insert_match PARAMS((char *, int, int, char *));
static int append_to_match PARAMS((char *, int, int, int));
static void insert_all_matches PARAMS((char **, int, char *));
static int complete_fncmp PARAMS((const char *, int, const char *, int));
static void display_matches PARAMS((char **));
static int compute_lcd_of_matches PARAMS((char **, int, const char *));
static int postprocess_matches PARAMS((char ***, int));
static int complete_get_screenwidth PARAMS((void));
static char *make_quoted_replacement PARAMS((char *, int, char *));
@ -157,10 +159,14 @@ int _rl_print_completions_horizontally;
#if defined (__MSDOS__) && !defined (__DJGPP__)
int _rl_completion_case_fold = 1;
#else
int _rl_completion_case_fold;
int _rl_completion_case_fold = 0;
#endif
/* If non-zero, don't match hidden files (filenames beginning with a `.' on
/* Non-zero means that `-' and `_' are equivalent when comparing filenames
for completion. */
int _rl_completion_case_map = 0;
/* If zero, don't match hidden files (filenames beginning with a `.' on
Unix) when doing filename completion. */
int _rl_match_hidden_files = 1;
@ -170,6 +176,10 @@ int _rl_match_hidden_files = 1;
display prefix replaced with an ellipsis. */
int _rl_completion_prefix_display_length = 0;
/* The readline-private number of screen columns to use when displaying
matches. If < 0 or > _rl_screenwidth, it is ignored. */
int _rl_completion_columns = -1;
/* Global variables available to applications using readline. */
#if defined (VISIBLE_STATS)
@ -185,6 +195,10 @@ int rl_visible_stats = 0;
after the `e' in `Makefile' won't result in `Makefilefile'. */
int _rl_skip_completed_text = 0;
/* If non-zero, menu completion displays the common prefix first in the
cycle of possible completions instead of the last. */
int _rl_menu_complete_prefix_first = 0;
/* If non-zero, then this is the address of a function to call when
completing on a directory name. The function is called with
the address of a string (the current directory name) as an arg. */
@ -467,6 +481,14 @@ get_y_or_n (for_pager)
{
int c;
/* For now, disable pager in callback mode, until we later convert to state
driven functions. Have to wait until next major version to add new
state definition, since it will change value of RL_STATE_DONE. */
#if defined (READLINE_CALLBACKS)
if (RL_ISSTATE (RL_STATE_CALLBACK))
return 1;
#endif
for (;;)
{
RL_SETSTATE(RL_STATE_MOREINPUT);
@ -829,7 +851,7 @@ print_filename (to_print, full_pathname, prefix_bytes)
if (path_isdir (new_full_pathname))
extension_char = '/';
free (new_full_pathname);
xfree (new_full_pathname);
to_print[-1] = c;
}
else
@ -844,7 +866,7 @@ print_filename (to_print, full_pathname, prefix_bytes)
extension_char = '/';
}
free (s);
xfree (s);
if (extension_char)
{
putc (extension_char, rl_outstream);
@ -1081,7 +1103,7 @@ remove_duplicate_matches (matches)
{
if (strcmp (matches[i], matches[i + 1]) == 0)
{
free (matches[i]);
xfree (matches[i]);
matches[i] = (char *)&dead_slot;
}
else
@ -1099,7 +1121,7 @@ remove_duplicate_matches (matches)
temp_array[j] = (char *)NULL;
if (matches[0] != (char *)&dead_slot)
free (matches[0]);
xfree (matches[0]);
/* Place the lowest common denominator back in [0]. */
temp_array[0] = lowest_common;
@ -1109,7 +1131,7 @@ remove_duplicate_matches (matches)
insert. */
if (j == 2 && strcmp (temp_array[0], temp_array[1]) == 0)
{
free (temp_array[1]);
xfree (temp_array[1]);
temp_array[1] = (char *)NULL;
}
return (temp_array);
@ -1288,7 +1310,7 @@ postprocess_matches (matchesp, matching_filenames)
if (rl_ignore_completion_duplicates)
{
temp_matches = remove_duplicate_matches (matches);
free (matches);
xfree (matches);
matches = temp_matches;
}
@ -1325,6 +1347,23 @@ postprocess_matches (matchesp, matching_filenames)
return (1);
}
static int
complete_get_screenwidth ()
{
int cols;
char *envcols;
cols = _rl_completion_columns;
if (cols >= 0 && cols <= _rl_screenwidth)
return cols;
envcols = getenv ("COLUMNS");
if (envcols && *envcols)
cols = atoi (envcols);
if (cols >= 0 && cols <= _rl_screenwidth)
return cols;
return _rl_screenwidth;
}
/* A convenience function for displaying a list of strings in
columnar format on readline's output stream. MATCHES is the list
of strings, in argv format, LEN is the number of strings in MATCHES,
@ -1334,7 +1373,7 @@ rl_display_match_list (matches, len, max)
char **matches;
int len, max;
{
int count, limit, printed_len, lines;
int count, limit, printed_len, lines, cols;
int i, j, k, l, common_length, sind;
char *temp, *t;
@ -1355,12 +1394,17 @@ rl_display_match_list (matches, len, max)
}
/* How many items of MAX length can we fit in the screen window? */
cols = complete_get_screenwidth ();
max += 2;
limit = _rl_screenwidth / max;
if (limit != 1 && (limit * max == _rl_screenwidth))
limit = cols / max;
if (limit != 1 && (limit * max == cols))
limit--;
/* Avoid a possible floating exception. If max > _rl_screenwidth,
/* If cols == 0, limit will end up -1 */
if (cols < _rl_screenwidth && limit < 0)
limit = 1;
/* Avoid a possible floating exception. If max > cols,
limit will be 0 and a divide-by-zero fault will result. */
if (limit == 0)
limit = 1;
@ -1608,7 +1652,7 @@ insert_match (match, start, mtype, qc)
else
_rl_replace_text (replacement, start, end);
if (replacement != match)
free (replacement);
xfree (replacement);
}
}
@ -1675,7 +1719,7 @@ append_to_match (text, delimiter, quote_char, nontrivial_match)
if (rl_point == rl_end && temp_string_index)
rl_insert_text (temp_string);
}
free (filename);
xfree (filename);
}
else
{
@ -1711,7 +1755,7 @@ insert_all_matches (matches, point, qc)
rl_insert_text (rp);
rl_insert_text (" ");
if (rp != matches[i])
free (rp);
xfree (rp);
}
}
else
@ -1720,7 +1764,7 @@ insert_all_matches (matches, point, qc)
rl_insert_text (rp);
rl_insert_text (" ");
if (rp != matches[0])
free (rp);
xfree (rp);
}
rl_end_undo_group ();
}
@ -1735,8 +1779,8 @@ _rl_free_match_list (matches)
return;
for (i = 0; matches[i]; i++)
free (matches[i]);
free (matches);
xfree (matches[i]);
xfree (matches);
}
/* Complete the word at or before point.
@ -1757,6 +1801,9 @@ rl_complete_internal (what_to_do)
int start, end, delimiter, found_quote, i, nontrivial_lcd;
char *text, *saved_line_buffer;
char quote_char;
#if 1
int tlen, mlen;
#endif
RL_SETSTATE(RL_STATE_COMPLETING);
@ -1784,7 +1831,11 @@ rl_complete_internal (what_to_do)
/* nontrivial_lcd is set if the common prefix adds something to the word
being completed. */
nontrivial_lcd = matches && strcmp (text, matches[0]) != 0;
free (text);
#if 1
if (what_to_do == '!' || what_to_do == '@')
tlen = strlen (text);
#endif
xfree (text);
if (matches == 0)
{
@ -1817,8 +1868,25 @@ rl_complete_internal (what_to_do)
case '!':
case '@':
/* Insert the first match with proper quoting. */
#if 0
if (*matches[0])
insert_match (matches[0], start, matches[1] ? MULT_MATCH : SINGLE_MATCH, &quote_char);
#else
if (what_to_do == TAB)
{
if (*matches[0])
insert_match (matches[0], start, matches[1] ? MULT_MATCH : SINGLE_MATCH, &quote_char);
}
else if (*matches[0] && matches[1] == 0)
/* should we perform the check only if there are multiple matches? */
insert_match (matches[0], start, matches[1] ? MULT_MATCH : SINGLE_MATCH, &quote_char);
else if (*matches[0]) /* what_to_do != TAB && multiple matches */
{
mlen = *matches[0] ? strlen (matches[0]) : 0;
if (mlen >= tlen)
insert_match (matches[0], start, matches[1] ? MULT_MATCH : SINGLE_MATCH, &quote_char);
}
#endif
/* If there are more matches, ring the bell to indicate.
If we are in vi mode, Posix.2 says to not ring the bell.
@ -1872,7 +1940,7 @@ rl_complete_internal (what_to_do)
if (saved_line_buffer)
{
completion_changed_buffer = strcmp (rl_line_buffer, saved_line_buffer) != 0;
free (saved_line_buffer);
xfree (saved_line_buffer);
}
RL_UNSETSTATE(RL_STATE_COMPLETING);
@ -1939,7 +2007,7 @@ rl_completion_matches (text, entry_function)
compute_lcd_of_matches (match_list, matches, text);
else /* There were no matches. */
{
free (match_list);
xfree (match_list);
match_list = (char **)NULL;
}
return (match_list);
@ -2005,6 +2073,62 @@ rl_username_completion_function (text, state)
#endif /* !__WIN32__ && !__OPENNT */
}
/* Return non-zero if CONVFN matches FILENAME up to the length of FILENAME
(FILENAME_LEN). If _rl_completion_case_fold is set, compare without
regard to the alphabetic case of characters. CONVFN is the possibly-
converted directory entry; FILENAME is what the user typed. */
static int
complete_fncmp (convfn, convlen, filename, filename_len)
const char *convfn;
int convlen;
const char *filename;
int filename_len;
{
register char *s1, *s2;
int d, len;
/* Otherwise, if these match up to the length of filename, then
it is a match. */
if (_rl_completion_case_fold && _rl_completion_case_map)
{
/* Case-insensitive comparison treating _ and - as equivalent */
if (filename_len == 0)
return 1;
if (convlen < filename_len)
return 0;
s1 = (char *)convfn;
s2 = (char *)filename;
len = filename_len;
do
{
d = _rl_to_lower (*s1) - _rl_to_lower (*s2);
/* *s1 == [-_] && *s2 == [-_] */
if ((*s1 == '-' || *s1 == '_') && (*s2 == '-' || *s2 == '_'))
d = 0;
if (d != 0)
return 0;
s1++; s2++; /* already checked convlen >= filename_len */
}
while (--len != 0);
return 1;
}
else if (_rl_completion_case_fold)
{
if ((_rl_to_lower (convfn[0]) == _rl_to_lower (filename[0])) &&
(convlen >= filename_len) &&
(_rl_strnicmp (filename, convfn, filename_len) == 0))
return 1;
}
else
{
if ((convfn[0] == filename[0]) &&
(convlen >= filename_len) &&
(strncmp (filename, convfn, filename_len) == 0))
return 1;
}
return 0;
}
/* Okay, now we write the entry_function for filename completion. In the
general case. Note that completion in the shell is a little different
because of all the pathnames that must be followed when looking up the
@ -2071,32 +2195,41 @@ rl_filename_completion_function (text, state)
/* We aren't done yet. We also support the "~user" syntax. */
/* Save the version of the directory that the user typed. */
users_dirname = savestring (dirname);
/* Save the version of the directory that the user typed, dequoting
it if necessary. */
if (rl_completion_found_quote && rl_filename_dequoting_function)
users_dirname = (*rl_filename_dequoting_function) (dirname, rl_completion_quote_character);
else
users_dirname = savestring (dirname);
if (*dirname == '~')
{
temp = tilde_expand (dirname);
free (dirname);
xfree (dirname);
dirname = temp;
}
/* We have saved the possibly-dequoted version of the directory name
the user typed. Now transform the directory name we're going to
pass to opendir(2). The directory rewrite hook modifies only the
directory name; the directory completion hook modifies both the
directory name passed to opendir(2) and the version the user
typed. Both the directory completion and rewrite hooks should perform
any necessary dequoting. The hook functions return 1 if they modify
the directory name argument. If either hook returns 0, it should
not modify the directory name pointer passed as an argument. */
if (rl_directory_rewrite_hook)
(*rl_directory_rewrite_hook) (&dirname);
/* The directory completion hook should perform any necessary
dequoting. */
if (rl_directory_completion_hook && (*rl_directory_completion_hook) (&dirname))
else if (rl_directory_completion_hook && (*rl_directory_completion_hook) (&dirname))
{
free (users_dirname);
xfree (users_dirname);
users_dirname = savestring (dirname);
}
else if (rl_completion_found_quote && rl_filename_dequoting_function)
{
/* delete single and double quotes */
temp = (*rl_filename_dequoting_function) (users_dirname, rl_completion_quote_character);
free (users_dirname);
users_dirname = temp;
xfree (dirname);
dirname = savestring (users_dirname);
}
directory = opendir (dirname);
@ -2105,7 +2238,7 @@ rl_filename_completion_function (text, state)
{
/* delete single and double quotes */
temp = (*rl_filename_dequoting_function) (filename, rl_completion_quote_character);
free (filename);
xfree (filename);
filename = temp;
}
filename_len = strlen (filename);
@ -2147,22 +2280,8 @@ rl_filename_completion_function (text, state)
}
else
{
/* Otherwise, if these match up to the length of filename, then
it is a match. */
if (_rl_completion_case_fold)
{
if ((_rl_to_lower (convfn[0]) == _rl_to_lower (filename[0])) &&
(convlen >= filename_len) &&
(_rl_strnicmp (filename, convfn, filename_len) == 0))
break;
}
else
{
if ((convfn[0] == filename[0]) &&
(convlen >= filename_len) &&
(strncmp (filename, convfn, filename_len) == 0))
break;
}
if (complete_fncmp (convfn, convlen, filename, filename_len))
break;
}
}
@ -2175,17 +2294,17 @@ rl_filename_completion_function (text, state)
}
if (dirname)
{
free (dirname);
xfree (dirname);
dirname = (char *)NULL;
}
if (filename)
{
free (filename);
xfree (filename);
filename = (char *)NULL;
}
if (users_dirname)
{
free (users_dirname);
xfree (users_dirname);
users_dirname = (char *)NULL;
}
@ -2225,7 +2344,7 @@ rl_filename_completion_function (text, state)
temp = savestring (convfn);
if (convfn != dentry)
free (convfn);
xfree (convfn);
return (temp);
}
@ -2304,14 +2423,14 @@ rl_old_menu_complete (count, invoking_key)
if (matches == 0 || postprocess_matches (&matches, matching_filenames) == 0)
{
rl_ding ();
rl_ding ();
FREE (matches);
matches = (char **)0;
FREE (orig_text);
orig_text = (char *)0;
completion_changed_buffer = 0;
RL_UNSETSTATE(RL_STATE_COMPLETING);
return (0);
completion_changed_buffer = 0;
RL_UNSETSTATE(RL_STATE_COMPLETING);
return (0);
}
RL_UNSETSTATE(RL_STATE_COMPLETING);
@ -2340,7 +2459,10 @@ rl_old_menu_complete (count, invoking_key)
match_list_index += count;
if (match_list_index < 0)
match_list_index += match_list_size;
{
while (match_list_index < 0)
match_list_index += match_list_size;
}
else
match_list_index %= match_list_size;
@ -2375,7 +2497,7 @@ rl_menu_complete (count, ignore)
static int full_completion = 0; /* set to 1 if menu completion should reinitialize on next call */
static int orig_start, orig_end;
static char quote_char;
static int delimiter;
static int delimiter, cstate;
/* The first time through, we generate the list of matches and set things
up to insert them. */
@ -2428,14 +2550,14 @@ rl_menu_complete (count, ignore)
if (matches == 0 || postprocess_matches (&matches, matching_filenames) == 0)
{
rl_ding ();
rl_ding ();
FREE (matches);
matches = (char **)0;
FREE (orig_text);
orig_text = (char *)0;
completion_changed_buffer = 0;
RL_UNSETSTATE(RL_STATE_COMPLETING);
return (0);
completion_changed_buffer = 0;
RL_UNSETSTATE(RL_STATE_COMPLETING);
return (0);
}
RL_UNSETSTATE(RL_STATE_COMPLETING);
@ -2483,6 +2605,11 @@ rl_menu_complete (count, ignore)
full_completion = 1;
return (0);
}
else if (_rl_menu_complete_prefix_first && match_list_size > 1)
{
rl_ding ();
return (0);
}
}
/* Now we have the list of matches. Replace the text between
@ -2500,7 +2627,10 @@ rl_menu_complete (count, ignore)
match_list_index += count;
if (match_list_index < 0)
match_list_index += match_list_size;
{
while (match_list_index < 0)
match_list_index += match_list_size;
}
else
match_list_index %= match_list_size;

Some files were not shown because too many files have changed in this diff Show More