Imported from ../bash-3.1.tar.gz.

This commit is contained in:
Jari Aalto 2005-12-07 14:08:12 +00:00
commit 95732b497d
267 changed files with 24541 additions and 18843 deletions

598
CHANGES
View file

@ -1,3 +1,599 @@
This document details the changes between this version, bash-3.1-release,
and the previous version, bash-3.1-rc2.
1. Changes to Readline
a. Several changes to the multibyte redisplay code to fix problems with
prompts containing invisible characters.
------------------------------------------------------------------------------
This document details the changes between this version, bash-3.1-rc2,
and the previous version, bash-3.1-rc1.
1. Changes to Bash
a. Fixed a bug that caused a DEBUG trap to overwrite a command string that's
eventually attached to a background job.
b. Changed some code so that filenames with leading tildes with spaces in the
name aren't tilde-expanded by the bash completion code.
c. Fixed a bug that caused the pushd builtin to fail to change to
directories with leading `-'.
d. Fixed a small memory leak in the programmable completion code.
2. Changes to Readline
a. Fixed a redisplay bug caused by moving the cursor vertically to a line
with invisible characters in the prompt in a multibyte locale.
b. Fixed a bug that could cause the terminal special chars to be bound in the
wrong keymap in vi mode.
3. New Features in Bash
a. If compiled for strict POSIX conformance, LINES and COLUMNS may now
override the true terminal size.
4. New Features in Readline
a. A new external application-controllable variable that allows the LINES
and COLUMNS environment variables to set the window size regardless of
what the kernel returns.
------------------------------------------------------------------------------
This document details the changes between this version, bash-3.1-rc1,
and the previous version, bash-3.1-beta1.
1. Changes to Bash
a. Fixed a bug that could cause core dumps due of accessing the current
pipeline while in the middle of modifying it.
b. Fixed a bug that caused pathnames with backslashes still quoting characters
to be passed to opendir().
c. Command word completion now obeys the setting of completion-ignore-case.
d. Fixed a problem with redirection that caused file descriptors greater than
2 to be inappropriately marked as close-on-exec.
e. In Posix mode, after `wait' is called to wait for a particular process
explicitly, that process is removed from the list of processes known to
the shell, and subsequent attempts to wait for it return errors.
f. Fixed a bug that caused extended pattern matching to incorrectly scan
backslash-escaped pattern characters.
g. Fixed a synchronization problem that could cause core dumps when handling
a SIGWINCH.
h. Fixed a bug that caused an unmatched backquote to be accepted without an
error when processing here documents.
i. Fixed a small memory leak in the `cd' builtin.
j. Fix for MacOS X so it gets the values for the HOSTTYPE, MACHTYPE, and
OSTYPE variables at build time, to support universal binaries.
k. Fixed a bug that could cause an exit trap to return the exit status of
the trap command rather than the status as it was before the trap was
run as the shell's exit status.
2. New Features in Bash
3. Changes to Readline
a. Fixed a bug that caused reversing the incremental search direction to
not work correctly.
b. Fixed the vi-mode `U' command to only undo up to the first time insert mode
was entered, as Posix specifies.
c. Fixed a bug in the vi-mode `r' command that left the cursor in the wrong
place.
4. New Features in Readline
a. New application-callable auxiliary function, rl_variable_value, returns
a string corresponding to a readline variable's value.
b. When parsing inputrc files and variable binding commands, the parser
strips trailing whitespace from values assigned to boolean variables
before checking them.
------------------------------------------------------------------------------
This document details the changes between this version, bash-3.1-beta1,
and the previous version, bash-3.1-alpha1.
1. Changes to Bash
a. Added some system-specific signal names.
b. Fixed a typo in the ulimit builtin to make `x' the right option to
maniuplate the limit on file locks.
c. Fixed a problem with using += to append to index 0 of an array variable
when not using subscript syntax.
d. A few changes to configure.in to remove calls to obsolete or outdated
macros.
e. Make sure changes to variables bash handles specially (e.g., LC_ALL) are
made when the variable is set in the temporary environment to a command.
f. Make sure changes to variables bash handles specially (e.g., LC_ALL) are
made when the variable is modified using `printf -v'.
g. The export environment is now remade on cygwin when HOME is changed, so
DLLs bash is linked against pick up the new value. This fixes problems
with tilde expansion when linking against and already-installed readline.
h. Small fix to the logic for performing tilde expansion in posix mode, so
expansion on the right-hand side of an assignment statement takes place.
i. Fixed a bug that prevented redirections associated with a shell function
from being executed when in a subshell.
j. Fixed `source' and `.' builtins to not require an executable file when
searching $PATH for a file to source.
k. Fixed a bug that caused incorrect word splitting in a function when IFS
was declared local, then unset.
l. Fixed a problem with the `kill' builtin that prevented sending signals
to a process group under certain circumstances when providing a pid < 0.
m. When in POSIX mode, `pwd' now checks that the value it prints is the same
directory as `.', even when displaying $PWD.
n. Fixed a problem with the `read' builtin when reading a script from standard
input and reading data from the same file.
o. Fixed a problem with the `type' and `command' builtins that caused absolute
pathnames to be displayed incorrectly.
p. Some changes to the `bg' builtin for POSIX conformance.
q. The `fc' builtin now removes the `fc' command that caused it to invoke an
editor on specified history entries from the history entirely, rather than
simply ignoring it.
r. When in POSIX mode, the `v' command in vi editing mode simply invokes vi
on the current command, rather than checking $FCEDIT and $EDITOR.
s. Fixed a small memory leak in the pathname canonicalization code.
t. Fixed a bug that caused the expanded value of a $'...' string to be
incorrectly re-quoted if it occurred within a double-quoted ${...}
parameter expansion.
u. Restored default emacs-mode key binding of M-TAB to dynamic-complete-history.
v. Fixed a bug that caused core dumps when interrupting loops running builtins
on some systems.
w. Make sure that some of the functions bash provides replacements for are
not cpp defines.
x. The code that scans embedded commands for the parser (`...` and $(...)) is
now more aware of embedded comments and their effect on quoted strings.
y. Changed the `-n' option to the `history' builtin to not reset the number of
history lines read in the current session after reading the new lines from
the history file if the history is being appended when it is written to
the file, since the appending takes care of the problem that the adjustment
was intended to solve.
z. Improved the error message displayed when a shell script fails to execute
because the environment and size of command line arguments are too large.
aa. A small fix to make sure that $HISTCMD is evaluated whenever the shell is
saving commands to the history list, not just when HISTSIZE is defined.
2. Changes to Readline
a. The `change-case' command now correctly changes the case of multibyte
characters.
b. Changes to the shared library construction scripts to deal with Windows
DLL naming conventions for Cygwin.
c. Fixed the redisplay code to avoid core dumps resulting from a poorly-timed
SIGWINCH.
d. Fixed the non-incremental search code in vi mode to dispose of any current
undo list when copying a line from the history into the current editing
buffer.
e. The variable assignment code now ignores whitespace at the end of lines
when assigning to boolean variables.
f. The `C-w' binding in incremental search now understands multibyte
characters.
3. New Features in Bash
a. A new configuration option, `--enable-strict-posix-default', which will
build bash to be POSIX conforming by default.
4. New Features in Readline
a. If the rl_completion_query_items is set to a value < 0, readline never
asks the user whether or not to view the possible completions.
------------------------------------------------------------------------------
This document details the changes between this version, bash-3.1-alpha1,
and the previous version, bash-3.0-release.
1. Changes to Bash
a. Fixed a bug that caused bash to crash if referencing an unset local array.
b. Fixed a problem that caused tilde expansion to not be performed before
attempting globbing word completion.
c. Fixed an incompatibility so that a first argument to trap that's a valid
signal number will be trated as a signal rather than a command to execute.
d. Fixed ${#word} expansion to correctly compute the length of a string
containing multibyte characters.
e. Fixed a bug that caused bash to not pass the correct flags for signal
disposition to child processes.
f. Fixed a bug that caused `fc -l' to list one too many history entries.
g. Some fixes to `fc' for POSIX conformance.
h. Some fixes to job status display for POSIX conformance.
i. Fixed a bug that caused `command -v' to display output if a command was not
found -- it should be silent.
j. In POSIX mode, `type' and `command -[vV]' do not report non-executable
files, even if the shell will attempt to execute them.
k. Fixed a bug that caused the `==' operator to the [[ command to not attempt
extended pattern matching.
l. Fixed the brace expansion code to handle characters whose value exceeds 128.
m. Fixed `printf' to handle strings with a leading `\0' whose length is
non-zero.
n. Fixed a couple of problems with brace expansion where `${' was handled
incorrectly.
o. Fixed off-by-one error when calculating the upper bound of `offset' when
processing the ${array[@]:offset:length} expansion.
p. System-specific configuration changes for: FreeBSD 5.x, Interix, MacOS X
10.4, Linux 2.4+ kernels, Linux 3.x kernels, Dragonfly BSD, QNX 6.x,
Cygwin
q. Fixed a bug that caused the shell to ignore the status of the rightmost
command in a pipeline when the `pipefail' option was enabled.
r. Fixed a completion bug that caused core dumps when expanding a directory
name.
s. Fixed a bug that prevented `hash -d' from removing commands from the hash
table.
t. Fixed word splitting to avoid really bad quadratic performance when
expanding long lists.
u. Fixed a bug that caused negative offsets in substring expansion to use the
wrong values.
v. Fixed a bug in printf that caused it to not return failure on write errors.
w. Fixed a bug that caused commands in subshells to not be properly timed.
x. The shell parser no longer attempts to parse a compound assignment specially
unless in a position where an assignment statement is acceptable or parsing
arguments to a builtin that accepts assignment statements.
y. Fixed a problem that caused a `case' statement to be added to the history
incorrectly as a single command if the `case word' was on one line and the
`in' on another.
z. Fixed a problem that caused internal shell quoting characters to be
incorrectly quoted with backslashes under some circumstances.
aa. The shell now performs correct word splitting when IFS contains multibyte
characters.
bb. The mail checking code now resets the cached file information if the size
drops to 0, even if the times don't change.
cc. A completed command name that is found in $PATH as well as the name of a
directory in the current directory no longer has a slash appended in certain
circumstances: a single instance found in $PATH when `.' is not in $PATH,
and multiple instances found in $PATH, even when `.' is in $PATH.
dd. Incorporated tilde expansion into the word expansion code rather than as a
separately-called function, fixing some cases where it was performed
inappropriately (e.g., after the second `=' in an assignment statement or
in a double-quoted parameter expansion).
ee. Fixed several bugs encountered when parsing compound assignment statements,
so that compound assignments appearing as arguments to builtins are no
longer double-expanded.
ff. Fixed a bug in the command execution code that caused asynchronous commands
containing command substitutions to not put the terminal in the wrong
process group.
gg. Bash now handles the case where the WCONTINUED flag causes waitpid() to
return -1/EINVAL at runtime as well as configuration time.
hh. Fixed parser to generate an error when the pipeline `argument' to `!' or
`time' is NULL.
ii. The shell now takes a little more care when manipulating file descriptors
greater than 9 with the `exec' builtin.
jj. Fixed a bug that caused variable assignments preceding the `command' builtin
preceding a special builtin to be preserved after the command completed in
POSIX mode.
kk. Fixed a bug that allowed variables beginning with a digit to be created.
ll. Fixed a bug that caused a \<newline> to be removed when parsing a $'...'
construct.
mm. A shell whose name begins with `-' will now be a restricted shell if the
remainder of the name indicates it should be restricted.
nn. Fixed a bug that could cause a core dump if FUNCNAME were changed or unset
during a function's execution.
oo. Fixed a bug that caused executing a `return' in a function to not execute
a RETURN trap. The RETURN trap is inherited by shell functions only if
function tracing is globally enabled or has been enabled for that function.
pp. Fixed cases where var[@] was not handled exactly like var, when var is a
scalar variable.
qq. Fixed a bug that caused the first character after a SIGINT to be discarded
under certain circumstances.
rr. Fixed exit status code so that a suspended job returns 128+signal as its
exit status (preventing commands after it in `&&' lists from being
executed).
ss. Fixed a bug that caused the shell parser state to be changed by executing
a shell function as a result of word completion.
tt. Fixed a long-standing bug that caused '\177' characters in variable
values to be discarded when expanded in double-quoted strings.
uu. Fixed a bug that caused $RANDOM to be re-seeded multiple times in a
subshell environment.
vv. Extensive changes to the job management code to avoid the pid-reuse and
pid-aliasing problems caused by retaining the exit status of too many jobs,
but still retain as many background job statuses as POSIX requires.
ww. Fixed a parser bug in processing \<newline> that caused things like
((echo 5) \
(echo 6))
to not work correctly.
xx. `pwd -P' now sets $PWD to a directory name containing no symbolic links
when in posix mode, as POSIX requires.
yy. In posix mode, bash no longer sets $PWD to a name containing no symbolic
links if a directory is chosen from $CDPATH.
zz. The word splitting code now treats an IFS character that is not space,
tab, or newline and any adjacent IFS white space as a single delimiter, as
SUSv3/XPG6 require.
aaa. The `read' builtin now checks whether or not the number of fields read is
exactly the same as the number of variables instead of just assigning the
rest of the line (minus any trailing IFS white space) to the last
variable. This is what POSIX/SUS/XPG all require.
bbb. Fixed a bug that caused `read' to always check whether or not fd 0 was a
pipe, even when reading from another file descriptor.
ccc. Fixed a bug that caused short-circuiting of execution even if the return
value was being inverted.
ddd. Fixed a bug that caused a core dump while decoding \W escapes in PS1 if
PWD was unset.
eee. Fixed a bug in `read' that counted internal quoting characters for the
purposes of `read -n'.
fff. Fixed a bug so that a function definition in a pipeline causes a child
process to be forked at the right time.
ggg. Bash will not attempt to link against a readline library that doesn't
have rl_gnu_readline_p == 1.
hhh. Fixed a bug that caused `read' to consume one too many characters when
reading a fixed number of characters and the Nth character is a backslash.
iii. Fixed a bug that caused `unset' on variables in the temporary environment
to leave them set when `unset' completed.
jjj. Fixed a bug that caused bash to close fd 2 if an `exec' failed and the
shell didn't exit.
kkk. The completion code is more careful to not turn `/' or `///' into `//',
for those systems on which `//' has special meaning.
lll. Fixed a bug that caused command substitution in asynchronous commands to
close the wrong file descriptors.
mmm. The shell no longer prints status messages about terminated background
processes unless job control is active.
nnn. Fixed a bug that prevented multiple consecutive invocations of `history -s'
from adding all the commands to the history list.
ooo. Added a couple of changes to make arithmetic expansion more consistent in
all its contexts (still not perfect).
ppp. Fixed a bug that caused the parser to occasionally not find the right
terminating "`" in an old-style command substitution.
qqq. Fixed a bug that caused core dumps when the shell was reading its non-
interactive input from fd 0 and fd 0 was duplicated and restored using a
combination of `exec' (to save) and redirection (to restore).
rrr. Fixed a problem that caused loops in sourced scripts to not be cleaned
up properly when a `return' is executed.
sss. Change internal command substitution completion function to append a slash
to directory names in the command.
2. Changes to Readline
a. Fixed a bug that caused multiliine prompts to be wrapped and displayed
incorrectly.
b. Fixed a bug that caused ^P/^N in emacs mode to fail to display the current
line correctly.
c. Fixed a problem in computing the number of invisible characters on the first
line of a prompt whose length exceeds the screen width.
d. Fixed vi-mode searching so that failure preserves the current line rather
than the last line in the history list.
e. Fixed the vi-mode `~' command (change-case) to have the correct behavior at
end-of-line when manipulating multibyte characters.
f. Fixed the vi-mode `r' command (change-char) to have the correct behavior at
end-of-line when manipulating multibyte characters.
g. Fixed multiple bugs in the redisplay of multibyte characters: displaying
prompts longer than the screen width containing multibyte characters,
h. Fix the calculation of the number of physical characters in the prompt
string when it contains multibyte characters.
i. A non-zero value for the `rl_complete_suppress_append' variable now causes
no `/' to be appended to a directory name.
j. Fixed forward-word and backward-word to work when words contained
multibyte characters.
k. Fixed a bug in finding the delimiter of a `?' substring when performing
history expansion in a locale that supports multibyte characters.
l. Fixed a memory leak caused by not freeing the timestamp in a history entry.
m. Fixed a bug that caused "\M-x" style key bindings to not obey the setting
of the `convert-meta' variable.
n. Fixed saving and restoring primary prompt when prompting for incremental
and non-incremental searches; search prompts now display multibyte
characters correctly.
o. Fixed a bug that caused keys originally bound to self-insert but shadowed
by a multi-character key sequence to not be inserted.
p. Fixed code so rl_prep_term_function and rl_deprep_term_function aren't
dereferenced if NULL (matching the documentation).
q. Extensive changes to readline to add enough state so that commands
requiring additional characters (searches, multi-key sequences, numeric
arguments, commands requiring an additional specifier character like
vi-mode change-char, etc.) work without synchronously waiting for
additional input.
r. Lots of changes so readline builds and runs on MinGW.
s. Readline no longer tries to modify the terminal settings when running in
callback mode.
t. The Readline display code no longer sets the location of the last invisible
character in the prompt if the \[\] sequence is empty.
3. New Features in Bash
a. Bash now understands LC_TIME as a special variable so that time display
tracks the current locale.
b. BASH_ARGC, BASH_ARGV, BASH_SOURCE, and BASH_LINENO are no longer created
as `invisible' variables and may not be unset.
c. In POSIX mode, if `xpg_echo' option is enabled, the `echo' builtin doesn't
try to interpret any options at all, as POSIX requires.
d. The `bg' builtin now accepts multiple arguments, as POSIX seems to specify.
e. Fixed vi-mode word completion and glob expansion to perform tilde
expansion.
f. The `**' mathematic exponentiation operator is now right-associative.
g. The `ulimit' builtin has new options: -i (max number of pending signals),
-q (max size of POSIX message queues), and -x (max number of file locks).
h. A bare `%' once again expands to the current job when used as a job
specifier.
i. The `+=' assignment operator (append to the value of a string or array) is
now supported for assignment statements and arguments to builtin commands
that accept assignment statements.
j. BASH_COMMAND now preserves its value when a DEBUG trap is executed.
k. The `gnu_errfmt' option is enabled automatically if the shell is running
in an emacs terminal window.
l. New configuration option: --single-help-strings. Causes long help text
to be written as a single string; intended to ease translation.
m. The COMP_WORDBREAKS variable now causes the list of word break characters
to be emptied when the variable is unset.
n. An unquoted expansion of $* when $IFS is empty now causes the positional
parameters to be concatenated if the expansion doesn't undergo word
splitting.
o. Bash now inherits $_ from the environment if it appears there at startup.
p. New shell option: nocasematch. If non-zero, shell pattern matching ignores
case when used by `case' and `[[' commands.
q. The `printf' builtin takes a new option: -v var. That causes the output
to be placed into var instead of on stdout.
r. By default, the shell no longer reports processes dying from SIGPIPE.
s. Bash now sets the extern variable `environ' to the export environment it
creates, so C library functions that call getenv() (and can't use the
shell-provided replacement) get current values of environment variables.
4. New Features in Readline
a. The key sequence sent by the keypad `delete' key is now automatically
bound to delete-char.
b. A negative argument to menu-complete now cycles backward through the
completion list.
c. A new bindable readline variable: bind-tty-special-chars. If non-zero,
readline will bind the terminal special characters to their readline
equivalents when it's called (on by default).
d. New bindable command: vi-rubout. Saves deleted text for possible
reinsertion, as with any vi-mode `text modification' command; `X' is bound
to this in vi command mode.
------------------------------------------------------------------------------
This document details the changes between this version, bash-3.0-release,
and the previous version, bash-3.0-rc1.
@ -184,7 +780,7 @@ n. Fixed the value of errno set by the pathname canonicalization functions.
o. Changed the grammar so that `time' alone on a line times a null command
rather than being a syntax error.
p. The pattern substitution coded no longer performs quote removal on the
p. The pattern substitution code no longer performs quote removal on the
pattern before trying to match it, as the pattern removal functions do.
q. Fixed a bug that could cause core dumps when checking whether a quoted

13
COMPAT
View file

@ -1,5 +1,5 @@
This document details the incompatibilites between this version of bash,
bash-3.0, and a previous widely-available version, bash-1.14 (which
bash-3.1, and a previous widely-available version, bash-1.14 (which
is still the `standard' version for a few Linux distributions). These
were discovered by users of bash-2.x and 3.x, so this list is not
comprehensive. Some of these incompatibilities occur between the current
@ -212,3 +212,14 @@ and bash-2.0 were significant.)
18. Bash no longer requires that the body of a function be a group command;
any compound command is accepted.
19. As of bash-3.0, the pattern substitution operators no longer perform
quote removal on the pattern before attempting the match. This is the
way the pattern removal functions behave, and is more consistent.
20. After bash-3.0 was released, I reimplemented tilde expansion, incorporating
it into the mainline word expansion code. This fixes the bug that caused
the results of tilde expansion to be re-expanded. There is one
incompatibility: a ${paramOPword} expansion within double quotes will not
perform tilde expansion on WORD. This is consistent with the other
expansions, and what POSIX specifies.

File diff suppressed because it is too large Load diff

45
INSTALL
View file

@ -191,13 +191,14 @@ the Bash `configure' recognizes.
Define if you are using the Andrew File System from Transarc.
`--with-bash-malloc'
Use the Bash version of `malloc' in `lib/malloc/malloc.c'. This
is not the same `malloc' that appears in GNU libc, but an older
version derived from the 4.2 BSD `malloc'. This `malloc' is very
fast, but wastes some space on each allocation. This option is
enabled by default. The `NOTES' file contains a list of systems
for which this should be turned off, and `configure' disables this
option automatically for a number of systems.
Use the Bash version of `malloc' in the directory `lib/malloc'.
This is not the same `malloc' that appears in GNU libc, but an
older version originally derived from the 4.2 BSD `malloc'. This
`malloc' is very fast, but wastes some space on each allocation.
This option is enabled by default. The `NOTES' file contains a
list of systems for which this should be turned off, and
`configure' disables this option automatically for a number of
systems.
`--with-curses'
Use the curses library instead of the termcap library. This should
@ -210,7 +211,7 @@ the Bash `configure' recognizes.
`--with-installed-readline[=PREFIX]'
Define this to make Bash link with a locally-installed version of
Readline rather than the version in `lib/readline'. This works
only with Readline 4.3 and later versions. If PREFIX is `yes' or
only with Readline 5.0 and later versions. If PREFIX is `yes' or
not supplied, `configure' uses the values of the make variables
`includedir' and `libdir', which are subdirectories of `prefix' by
default, to find the installed version of Readline if it is not in
@ -291,6 +292,9 @@ does not provide the necessary support.
`=~' binary operator in the `[[' conditional command. (*note
Conditional Constructs::).
`--enable-debugger'
Include support for the bash debugger (distributed separately).
`--enable-directory-stack'
Include support for a `csh'-like directory stack and the `pushd',
`popd', and `dirs' builtins (*note The Directory Stack::).
@ -334,17 +338,17 @@ does not provide the necessary support.
This enables process substitution (*note Process Substitution::) if
the operating system provides the necessary support.
`--enable-progcomp'
Enable the programmable completion facilities (*note Programmable
Completion::). If Readline is not enabled, this option has no
effect.
`--enable-prompt-string-decoding'
Turn on the interpretation of a number of backslash-escaped
characters in the `$PS1', `$PS2', `$PS3', and `$PS4' prompt
strings. See *Note Printing a Prompt::, for a complete list of
prompt string escape sequences.
`--enable-progcomp'
Enable the programmable completion facilities (*note Programmable
Completion::). If Readline is not enabled, this option has no
effect.
`--enable-readline'
Include support for command-line editing and history with the Bash
version of the Readline library (*note Command Line Editing::).
@ -358,6 +362,19 @@ does not provide the necessary support.
Include the `select' builtin, which allows the generation of simple
menus (*note Conditional Constructs::).
`--enable-separate-helpfiles'
Use external files for the documentation displayed by the `help'
builtin instead of storing the text internally.
`--enable-single-help-strings'
Store the text displayed by the `help' builtin as a single string
for each help topic. This aids in translating the text to
different languages. You may need to disable this if your
compiler cannot handle very long string literals.
`--enable-strict-posix-default'
Make Bash POSIX-conformant by default (*note Bash POSIX Mode::).
`--enable-usg-echo-default'
A synonym for `--enable-xpg-echo-default'.
@ -366,7 +383,7 @@ does not provide the necessary support.
default, without requiring the `-e' option. This sets the default
value of the `xpg_echo' shell option to `on', which makes the Bash
`echo' behave more like the version specified in the Single Unix
Specification, version 2. *Note Bash Builtins::, for a
Specification, version 3. *Note Bash Builtins::, for a
description of the escape sequences that `echo' recognizes.
The file `config-top.h' contains C Preprocessor `#define' statements

View file

@ -35,7 +35,6 @@ lib/sh d
lib/termcap d
lib/termcap/grot d
lib/tilde d
lib/tilde/doc d
po d
support d
tests d
@ -409,6 +408,7 @@ lib/sh/strftime.c f
lib/sh/strindex.c f
lib/sh/stringlist.c f
lib/sh/stringvec.c f
lib/sh/strnlen.c f
lib/sh/strpbrk.c f
lib/sh/strstr.c f
lib/sh/strtod.c f
@ -423,6 +423,7 @@ lib/sh/times.c f
lib/sh/timeval.c f
lib/sh/tmpfile.c f
lib/sh/vprint.c f
lib/sh/winsize.c f
lib/sh/xstrchr.c f
lib/sh/zcatfd.c f
lib/sh/zread.c f
@ -450,8 +451,6 @@ lib/termcap/grot/COPYING f
lib/termcap/grot/README f
lib/tilde/README f
lib/tilde/Makefile.in f
lib/tilde/doc/tilde.texi f
lib/tilde/doc/Makefile f
lib/tilde/tilde.c f
lib/tilde/tilde.h f
lib/tilde/shell.c f
@ -463,7 +462,6 @@ po/Rules-builtins f
po/Rules-quot f
po/bash.pot f
po/boldquot.sed f
po/builtins.pot f
po/en@quot.header f
po/en@boldquot.header f
po/en@quot.po f
@ -529,6 +527,7 @@ support/xenix-link.sh f 755
support/shobj-conf f 755
support/rlvers.sh f 755
examples/bashdb/PERMISSION f
examples/bashdb/README f
examples/bashdb/bashdb f
examples/bashdb/bashdb.el f
examples/obashdb/PERMISSION f
@ -678,6 +677,8 @@ examples/misc/cshtobash f
tests/README f
tests/alias.tests f
tests/alias.right f
tests/appendop.tests f
tests/appendop.right f
tests/arith-for.tests f
tests/arith-for.right f
tests/arith.tests f
@ -686,6 +687,9 @@ tests/arith1.sub f
tests/arith2.sub f
tests/array.tests f
tests/array.right f
tests/array1.sub f
tests/array2.sub f
tests/array3.sub f
tests/array-at-star f
tests/array2.right f
tests/braces.tests f
@ -712,6 +716,7 @@ tests/dollar-at-star f
tests/dollar-at1.sub f
tests/dollar-at2.sub f
tests/dollar-star1.sub f
tests/dollar-star2.sub f
tests/dollar.right f
tests/dstack.tests f
tests/dstack.right f
@ -734,6 +739,8 @@ tests/extglob.tests f
tests/extglob.right f
tests/extglob2.tests f
tests/extglob2.right f
tests/extglob3.tests f
tests/extglob3.right f
tests/func.tests f
tests/func.right f
tests/func1.sub f
@ -759,12 +766,18 @@ tests/histexp.tests f
tests/histexp.right f
tests/history.tests f
tests/history.right f
tests/history.list f
tests/history.list f 444
tests/ifs.tests f
tests/ifs.right f
tests/ifs-posix.tests f
tests/ifs-posix.right f
tests/input-line.sh f
tests/input-line.sub f
tests/input.right f
tests/intl.tests f
tests/intl.right f
tests/iquote.tests f
tests/iquote.right f
tests/invert.tests f
tests/invert.right f
tests/jobs.tests f
@ -780,6 +793,7 @@ tests/new-exp1.sub f
tests/new-exp2.sub f
tests/new-exp3.sub f
tests/new-exp4.sub f
tests/new-exp5.sub f
tests/new-exp.right f
tests/nquote.tests f
tests/nquote.right f
@ -819,6 +833,7 @@ tests/redir4.sub f
tests/redir4.in1 f
tests/redir5.sub f
tests/redir6.sub f
tests/redir7.sub f
tests/rhs-exp.tests f
tests/rhs-exp.right f
tests/rsh.tests f
@ -826,6 +841,7 @@ tests/rsh.right f
tests/run-all f
tests/run-minimal f
tests/run-alias f
tests/run-appendop f
tests/run-arith-for f
tests/run-arith f
tests/run-array f
@ -843,6 +859,7 @@ tests/run-execscript f
tests/run-exp-tests f
tests/run-extglob f
tests/run-extglob2 f
tests/run-extglob3 f
tests/run-func f
tests/run-getopts f
tests/run-glob-test f
@ -851,7 +868,10 @@ tests/run-herestr f
tests/run-histexpand f
tests/run-history f
tests/run-ifs f
tests/run-ifs-posix f
tests/run-input-test f
tests/run-intl f
tests/run-iquote f
tests/run-invert f
tests/run-jobs f
tests/run-more-exp f
@ -876,6 +896,7 @@ tests/run-shopt f
tests/run-strip f
tests/run-test f
tests/run-tilde f
tests/run-tilde2 f
tests/run-trap f
tests/run-type f
tests/run-varenv f
@ -889,8 +910,10 @@ tests/strip.tests f
tests/strip.right f
tests/test.tests f
tests/test.right f
tests/tilde-tests f
tests/tilde.tests f
tests/tilde.right f
tests/tilde2.tests f
tests/tilde2.right f
tests/trap.tests f
tests/trap.right f
tests/trap1.sub f 755

24
MANIFEST.doc Normal file
View file

@ -0,0 +1,24 @@
#
# Master Manifest file for documentation-only distribution
#
doc d
MANIFEST.doc f
doc/article.ps f
doc/rose94.ps f
doc/bash.ps f
doc/bashbug.ps f
doc/builtins.ps f
doc/rbash.ps f
doc/bashref.ps f
doc/bashref.dvi f
doc/bash.0 f
doc/bashbug.0 f
doc/builtins.0 f
doc/rbash.0 f
doc/article.txt f
doc/bash.html f
doc/bashref.html f
doc/article.pdf f
doc/bash.pdf f
doc/bashref.pdf f
doc/rose94.pdf f

View file

@ -1,6 +1,6 @@
# Makefile for bash-3.0, version 2.152
# Makefile for bash-3.1, version 2.157
#
# Copyright (C) 1996-2004 Free Software Foundation, Inc.
# Copyright (C) 1996-2005 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
@ -67,6 +67,7 @@ RM = rm -f
AR = @AR@
ARFLAGS = @ARFLAGS@
RANLIB = @RANLIB@
SIZE = @SIZE@
INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
@ -116,10 +117,10 @@ THIS_SH = $(BUILD_DIR)/$(Program)
PROFILE_FLAGS= @PROFILE_FLAGS@
CFLAGS = @CFLAGS@
CFLAGS_FOR_BUILD = @CFLAGS_FOR_BUILD@
CFLAGS_FOR_BUILD = @CFLAGS_FOR_BUILD@ @CROSS_COMPILE@
CPPFLAGS = @CPPFLAGS@
CPPFLAGS_FOR_BUILD = @CPPFLAGS_FOR_BUILD@
LOCAL_CFLAGS = @LOCAL_CFLAGS@ ${DEBUG}
LOCAL_CFLAGS = @LOCAL_CFLAGS@ ${DEBUG} ${MALLOC_DEBUG}
DEFS = @DEFS@
LOCAL_DEFS = @LOCAL_DEFS@
@ -196,7 +197,8 @@ SHLIB_SOURCE = ${SH_LIBSRC}/clktck.c ${SH_LIBSRC}/getcwd.c \
${SH_LIBSRC}/fmtumax.c ${SH_LIBSRC}/netconn.c \
${SH_LIBSRC}/mktime.c ${SH_LIBSRC}/strftime.c \
${SH_LIBSRC}/memset.c ${SH_LIBSRC}/xstrchr.c \
${SH_LIBSRC}/zcatfd.c ${SH_LIBSRC}/shmatch.c
${SH_LIBSRC}/zcatfd.c ${SH_LIBSRC}/shmatch.c \
${SH_LIBSRC}/strnlen.c ${SH_LIBSRC}/winsize.c
SHLIB_LIB = -lsh
SHLIB_LIBNAME = libsh.a
@ -309,7 +311,7 @@ TILDE_LIBSRC = $(LIBSRC)/tilde
TILDE_LIBDIR = $(dot)/$(LIBSUBDIR)/tilde
TILDE_ABSSRC = ${topdir}/$(TILDE_LIBDIR)
TILDE_LIB = -ltilde
TILDE_LIB = @TILDE_LIB@
TILDE_LIBRARY = $(TILDE_LIBDIR)/libtilde.a
TILDE_LDFLAGS = -L$(TILDE_LIBDIR)
TILDE_DEP = $(TILDE_LIBRARY)
@ -513,7 +515,7 @@ $(Program): .build $(OBJECTS) $(BUILTINS_DEP) $(LIBDEP)
$(RM) $@
$(PURIFY) $(CC) $(BUILTINS_LDFLAGS) $(LIBRARY_LDFLAGS) $(LDFLAGS) -o $(Program) $(OBJECTS) $(LIBS)
ls -l $(Program)
size $(Program)
-$(SIZE) $(Program)
.build: $(SOURCES) config.h Makefile version.h $(VERSPROG)
@echo
@ -535,7 +537,7 @@ bashbug: $(SUPPORT_SRC)bashbug.sh config.h Makefile $(VERSPROG)
strip: $(Program) .made
strip $(Program)
ls -l $(Program)
size $(Program)
-$(SIZE) $(Program)
lint:
${MAKE} ${MFLAGS} CFLAGS='${GCC_LINT_FLAGS}' .made
@ -617,7 +619,7 @@ mksyntax$(EXEEXT): ${srcdir}/mksyntax.c config.h syntax.h ${BASHINCDIR}/chartype
# *not* cross-compiling
lsignames.h: mksignames$(EXEEXT)
$(RM) $@
./mksignames $@
./mksignames$(EXEEXT) $@
# copy the correct signames header file to signames.h
signames.h: $(SIGNAMES_H)
@ -625,7 +627,7 @@ signames.h: $(SIGNAMES_H)
syntax.c: mksyntax${EXEEXT} $(srcdir)/syntax.h
$(RM) $@
./mksyntax -o $@
./mksyntax$(EXEEXT) -o $@
$(BUILTINS_LIBRARY): $(BUILTIN_DEFS) $(BUILTIN_C_SRC) config.h ${BASHINCDIR}/memalloc.h version.h
@(cd $(DEFDIR) && $(MAKE) $(MFLAGS) DEBUG=${DEBUG} libbuiltins.a ) || exit 1
@ -668,7 +670,7 @@ $(srcdir)/configure: $(srcdir)/configure.in $(srcdir)/aclocal.m4 $(srcdir)/confi
# for chet
reconfig: force
sh $(srcdir)/configure
sh $(srcdir)/configure -C
#newversion: mkversion
# $(RM) .build
@ -728,7 +730,7 @@ LIB_SUBDIRS = ${RL_LIBDIR} ${HIST_LIBDIR} ${TERM_LIBDIR} ${GLOB_LIBDIR} \
basic-clean:
$(RM) $(OBJECTS) $(Program) bashbug
$(RM) .build .made version.h pathnames.h
$(RM) .build .made version.h
clean: basic-clean
( cd $(DOCDIR) && $(MAKE) $(MFLAGS) $@ )
@ -758,7 +760,7 @@ distclean: basic-clean maybe-clean
done
-( cd $(PO_DIR) ; $(MAKE) $(MFLAGS) DESTDIR=$(DESTDIR) $@ )
$(RM) $(CREATED_CONFIGURE) tags TAGS
$(RM) $(CREATED_SUPPORT) Makefile $(CREATED_MAKEFILES)
$(RM) $(CREATED_SUPPORT) Makefile $(CREATED_MAKEFILES) pathnames.h
maintainer-clean: basic-clean
@echo This command is intended for maintainers to use.
@ -772,7 +774,7 @@ maintainer-clean: basic-clean
done
-( cd $(PO_DIR) ; $(MAKE) $(MFLAGS) DESTDIR=$(DESTDIR) $@ )
$(RM) $(CREATED_CONFIGURE) $(CREATED_MAKEFILES)
$(RM) $(CREATED_SUPPORT) Makefile
$(RM) $(CREATED_SUPPORT) Makefile pathnames.h
maybe-clean:
-if test "X$(topdir)" != "X$(BUILD_DIR)" ; then \
@ -792,7 +794,7 @@ test tests check: force $(Program) $(TESTS_SUPPORT)
@-test -d tests || mkdir tests
@cp $(TESTS_SUPPORT) tests
@( cd $(srcdir)/tests && \
PATH=$$PATH:$(BUILD_DIR)/tests THIS_SH=$(THIS_SH) $(SHELL) ${TESTSCRIPT} )
PATH=$(BUILD_DIR)/tests:$$PATH THIS_SH=$(THIS_SH) $(SHELL) ${TESTSCRIPT} )
symlinks:
$(SHELL) $(SUPPORT_SRC)fixlinks -s $(srcdir)

88
NEWS
View file

@ -1,3 +1,91 @@
This is a terse description of the new features added to bash-3.1 since
the release of bash-3.0. As always, the manual page (doc/bash.1) is
the place to look for complete descriptions.
1. New Features in Bash
a. Bash now understands LC_TIME as a special variable so that time display
tracks the current locale.
b. BASH_ARGC, BASH_ARGV, BASH_SOURCE, and BASH_LINENO are no longer created
as `invisible' variables and may not be unset.
c. In POSIX mode, if `xpg_echo' option is enabled, the `echo' builtin doesn't
try to interpret any options at all, as POSIX requires.
d. The `bg' builtin now accepts multiple arguments, as POSIX seems to specify.
e. Fixed vi-mode word completion and glob expansion to perform tilde
expansion.
f. The `**' mathematic exponentiation operator is now right-associative.
g. The `ulimit' builtin has new options: -i (max number of pending signals),
-q (max size of POSIX message queues), and -x (max number of file locks).
h. A bare `%' once again expands to the current job when used as a job
specifier.
i. The `+=' assignment operator (append to the value of a string or array) is
now supported for assignment statements and arguments to builtin commands
that accept assignment statements.
j. BASH_COMMAND now preserves its value when a DEBUG trap is executed.
k. The `gnu_errfmt' option is enabled automatically if the shell is running
in an emacs terminal window.
l. New configuration option: --single-help-strings. Causes long help text
to be written as a single string; intended to ease translation.
m. The COMP_WORDBREAKS variable now causes the list of word break characters
to be emptied when the variable is unset.
n. An unquoted expansion of $* when $IFS is empty now causes the positional
parameters to be concatenated if the expansion doesn't undergo word
splitting.
o. Bash now inherits $_ from the environment if it appears there at startup.
p. New shell option: nocasematch. If non-zero, shell pattern matching ignores
case when used by `case' and `[[' commands.
q. The `printf' builtin takes a new option: -v var. That causes the output
to be placed into var instead of on stdout.
r. By default, the shell no longer reports processes dying from SIGPIPE.
s. Bash now sets the extern variable `environ' to the export environment it
creates, so C library functions that call getenv() (and can't use the
shell-provided replacement) get current values of environment variables.
t. A new configuration option, `--enable-strict-posix-default', which will
build bash to be POSIX conforming by default.
u. If compiled for strict POSIX conformance, LINES and COLUMNS may now
override the true terminal size.
2. New Features in Readline
a. The key sequence sent by the keypad `delete' key is now automatically
bound to delete-char.
b. A negative argument to menu-complete now cycles backward through the
completion list.
c. A new bindable readline variable: bind-tty-special-chars. If non-zero,
readline will bind the terminal special characters to their readline
equivalents when it's called (on by default).
d. New bindable command: vi-rubout. Saves deleted text for possible
reinsertion, as with any vi-mode `text modification' command; `X' is bound
to this in vi command mode.
e. A new external application-controllable variable that allows the LINES
and COLUMNS environment variables to set the window size regardless of
what the kernel returns: rl_prefer_env_winsize
-------------------------------------------------------------------------------
This is a terse description of the new features added to bash-3.0 since
the release of bash-2.05b. As always, the manual page (doc/bash.1) is
the place to look for complete descriptions.

95
POSIX
View file

@ -1,5 +1,5 @@
Bash POSIX Mode
===============
6.11 Bash POSIX Mode
====================
Starting Bash with the `--posix' command-line option or executing `set
-o posix' while Bash is running will cause Bash to conform more closely
@ -22,58 +22,59 @@ The following list is what's changed when `POSIX mode' is in effect:
is stopped is `Stopped(SIGNAME)', where SIGNAME is, for example,
`SIGTSTP'.
4. Reserved words may not be aliased.
4. The `bg' builtin uses the required format to describe each job
placed in the background, which does not include an indication of
whether the job is the current or previous job.
5. The POSIX 1003.2 `PS1' and `PS2' expansions of `!' to the history
5. Reserved words appearing in a context where reserved words are
recognized do not undergo alias expansion.
6. The POSIX 1003.2 `PS1' and `PS2' expansions of `!' to the history
number and `!!' to `!' are enabled, and parameter expansion is
performed on the values of `PS1' and `PS2' regardless of the
setting of the `promptvars' option.
6. The POSIX 1003.2 startup files are executed (`$ENV') rather than
7. The POSIX 1003.2 startup files are executed (`$ENV') rather than
the normal Bash files.
7. Tilde expansion is only performed on assignments preceding a
8. Tilde expansion is only performed on assignments preceding a
command name, rather than on all assignment statements on the line.
8. The default history file is `~/.sh_history' (this is the default
9. The default history file is `~/.sh_history' (this is the default
value of `$HISTFILE').
9. The output of `kill -l' prints all the signal names on a single
10. The output of `kill -l' prints all the signal names on a single
line, separated by spaces, without the `SIG' prefix.
10. The `kill' builtin does not accept signal names with a `SIG'
11. The `kill' builtin does not accept signal names with a `SIG'
prefix.
11. Non-interactive shells exit if FILENAME in `.' FILENAME is not
12. Non-interactive shells exit if FILENAME in `.' FILENAME is not
found.
12. Non-interactive shells exit if a syntax error in an arithmetic
13. Non-interactive shells exit if a syntax error in an arithmetic
expansion results in an invalid expression.
13. Redirection operators do not perform filename expansion on the word
14. Redirection operators do not perform filename expansion on the word
in the redirection unless the shell is interactive.
14. Redirection operators do not perform word splitting on the word in
15. Redirection operators do not perform word splitting on the word in
the redirection.
15. Function names must be valid shell `name's. That is, they may not
16. 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.
16. POSIX 1003.2 `special' builtins are found before shell functions
17. POSIX 1003.2 special builtins are found before shell functions
during command lookup.
17. If a POSIX 1003.2 special builtin returns an error status, a
18. If a POSIX 1003.2 special builtin returns an error status, a
non-interactive shell exits. The fatal errors are those listed in
the POSIX.2 standard, and include things like passing incorrect
options, redirection errors, variable assignment errors for
assignments preceding the command name, and so on.
18. If the `cd' builtin finds a directory to change to using
`$CDPATH', the value it assigns to the `PWD' variable does not
contain any symbolic links, as if `cd -P' had been executed.
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
@ -105,9 +106,10 @@ The following list is what's changed when `POSIX mode' is in effect:
27. 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. If users want to reset the handler for a
given signal to the original disposition, they should use `-' as
the first argument.
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
for the filename argument if it is not found by searching `PATH'.
@ -134,19 +136,44 @@ The following list is what's changed when `POSIX mode' is in effect:
argument does not refer to an existing directory, `cd' will fail
instead of falling back to PHYSICAL mode.
There is other POSIX 1003.2 behavior that Bash does not implement.
Specifically:
35. When the `pwd' builtin is supplied the `-P' option, it resets
`$PWD' to a pathname containing no symlinks.
1. Assignment statements affect the execution environment of all
builtins, not just special ones.
36. 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.
2. When a subshell is created to execute a shell script with execute
permission, but without a leading `#!', Bash sets `$0' to the full
pathname of the script as found by searching `$PATH', rather than
the command as typed by the user.
37. When listing the history, the `fc' builtin does not include an
indication of whether or not a history entry has been modified.
3. When using `.' to source a shell script found in `$PATH', bash
checks execute permission bits rather than read permission bits,
just as if it were searching for a command.
38. The default editor used by `fc' is `ed'.
39. 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
the `v' command is run, instead of checking `$FCEDIT' and
`$EDITOR'.
41. 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.
There is other POSIX 1003.2 behavior that Bash does not implement by
default even when in POSIX mode. Specifically:
1. The `fc' builtin checks `$EDITOR' as a program to edit history
entries if `FCEDIT' is unset, rather than defaulting directly to
`ed'. `fc' uses `ed' if `EDITOR' is unset.
2. As noted above, Bash requires the `xpg_echo' option to be enabled
for the `echo' builtin to be fully conformant.
Bash can be configured to be POSIX-conformant by default, by specifying
the `--enable-strict-posix-default' to `configure' when building (*note
Optional Features::).

4
RBASH
View file

@ -1,5 +1,5 @@
The Restricted Shell
====================
6.10 The Restricted Shell
=========================
If Bash is started with the name `rbash', or the `--restricted' or `-r'
option is supplied at invocation, the shell becomes restricted. A

2
README
View file

@ -1,7 +1,7 @@
Introduction
============
This is GNU Bash, version 3.0. Bash is the GNU Project's Bourne
This is GNU Bash, version 3.1. Bash is the GNU Project's Bourne
Again SHell, a complete implementation of the POSIX.2 shell spec,
but also with interactive command line editing, job control on
architectures that support it, csh-like features such as history

52
aclocal.m4 vendored
View file

@ -1541,7 +1541,14 @@ AC_DEFUN(BASH_CHECK_DEV_FD,
[AC_MSG_CHECKING(whether /dev/fd is available)
AC_CACHE_VAL(bash_cv_dev_fd,
[if test -d /dev/fd && test -r /dev/fd/0 < /dev/null; then
bash_cv_dev_fd=standard
# check for systems like FreeBSD 5 that only provide /dev/fd/[012]
exec 3<&0
if test -r /dev/fd/3; then
bash_cv_dev_fd=standard
else
bash_cv_dev_fd=absent
fi
exec 3<&-
elif test -d /proc/self/fd && test -r /proc/self/fd/0 < /dev/null; then
bash_cv_dev_fd=whacky
else
@ -1733,12 +1740,18 @@ AC_CACHE_VAL(ac_cv_rl_version,
#include <stdio.h>
#include <readline/readline.h>
extern int rl_gnu_readline_p;
main()
{
FILE *fp;
fp = fopen("conftest.rlv", "w");
if (fp == 0) exit(1);
fprintf(fp, "%s\n", rl_library_version ? rl_library_version : "0.0");
if (fp == 0)
exit(1);
if (rl_gnu_readline_p != 1)
fprintf(fp, "0.0\n");
else
fprintf(fp, "%s\n", rl_library_version ? rl_library_version : "0.0");
fclose(fp);
exit(0);
}
@ -1852,6 +1865,39 @@ AC_DEFINE(CTYPE_NON_ASCII)
fi
])
AC_DEFUN(BASH_CHECK_WCONTINUED,
[
AC_MSG_CHECKING(whether WCONTINUED flag to waitpid is unavailable or available but broken)
AC_CACHE_VAL(bash_cv_wcontinued_broken,
[AC_TRY_RUN([
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <errno.h>
#ifndef errno
extern int errno;
#endif
main()
{
int x;
x = waitpid(-1, (int *)0, WNOHANG|WCONTINUED);
if (x == -1 && errno == EINVAL)
exit (1);
else
exit (0);
}
], bash_cv_wcontinued_broken=no,bash_cv_wcontinued_broken=yes,
[AC_MSG_WARN(cannot check WCONTINUED if cross compiling -- defaulting to no)
bash_cv_wcontinued_broken=no]
)])
AC_MSG_RESULT($bash_cv_wcontinued_broken)
if test $bash_cv_wcontinued_broken = yes; then
AC_DEFINE(WCONTINUED_BROKEN)
fi
])
dnl
dnl tests added for bashdb
dnl

24
array.c
View file

@ -107,7 +107,7 @@ ARRAY *a;
ARRAY *a1;
ARRAY_ELEMENT *ae, *new;
if (!a)
if (a == 0)
return((ARRAY *) NULL);
a1 = array_create();
a1->type = a->type;
@ -243,9 +243,9 @@ char *s;
{
register ARRAY_ELEMENT *ae, *new;
if (a == 0)
if (a == 0 || (array_empty(a) && s == 0))
return 0;
if (n <= 0)
else if (n <= 0)
return (a->num_elements);
ae = element_forw(a->head);
@ -253,16 +253,18 @@ char *s;
new = array_create_element(0, s);
ADD_BEFORE(ae, new);
a->num_elements++;
if (array_num_elements(a) == 1) /* array was empty */
return 1;
}
a->max_index += n;
/*
* Renumber all elements in the array except the one we just added.
*/
for ( ; ae != a->head; ae = element_forw(ae))
element_index(ae) += n;
a->max_index = element_index(a->head->prev);
return (a->num_elements);
}
@ -288,7 +290,7 @@ ARRAY *array;
ARRAY_ELEMENT *a;
char *t;
if (array == 0 || array->head == 0 || array_empty (array))
if (array == 0 || array_head(array) == 0 || array_empty(array))
return (ARRAY *)NULL;
for (a = element_forw(array->head); a != array->head; a = element_forw(a)) {
t = quote_string (a->value);
@ -313,7 +315,7 @@ int starsub, quoted;
arrayind_t i;
char *ifs, sep[2];
p = array_head (a);
p = a ? array_head (a) : 0;
if (p == 0 || array_empty (a) || start > array_max_index(a))
return ((char *)NULL);
@ -354,10 +356,10 @@ int mflags;
ARRAY_ELEMENT *e;
char *t, *ifs, sifs[2];
if (array_head (a) == 0 || array_empty (a))
if (a == 0 || array_head(a) == 0 || array_empty(a))
return ((char *)NULL);
a2 = array_copy (a);
a2 = array_copy(a);
for (e = element_forw(a2->head); e != a2->head; e = element_forw(e)) {
t = pat_subst(element_value(e), pat, rep, mflags);
FREE(element_value(e));
@ -427,7 +429,7 @@ char *v;
{
register ARRAY_ELEMENT *new, *ae;
if (!a)
if (a == 0)
return(-1);
new = array_create_element(i, v);
if (i > array_max_index(a)) {
@ -473,7 +475,7 @@ arrayind_t i;
{
register ARRAY_ELEMENT *ae;
if (!a || array_empty(a))
if (a == 0 || array_empty(a))
return((ARRAY_ELEMENT *) NULL);
for (ae = element_forw(a->head); ae != a->head; ae = element_forw(ae))
if (element_index(ae) == i) {

View file

@ -1,6 +1,6 @@
/* arrayfunc.c -- High-level array functions used by other parts of the shell. */
/* Copyright (C) 2001-2003 Free Software Foundation, Inc.
/* Copyright (C) 2001-2005 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@ -37,6 +37,9 @@
extern char *this_command_name;
extern int last_command_exit_value;
extern int array_needs_making;
static SHELL_VAR *bind_array_var_internal __P((SHELL_VAR *, arrayind_t, char *, int));
static void quote_array_assignment_chars __P((WORD_LIST *));
static char *array_value_internal __P((char *, int, int, int *));
@ -72,6 +75,8 @@ convert_var_to_array (var)
var->assign_func = (sh_var_assign_func_t *)NULL;
INVALIDATE_EXPORTSTR (var);
if (exported_p (var))
array_needs_making++;
VSETATTR (var, att_array);
VUNSETATTR (var, att_invisible);
@ -79,6 +84,49 @@ convert_var_to_array (var)
return var;
}
static SHELL_VAR *
bind_array_var_internal (entry, ind, value, flags)
SHELL_VAR *entry;
arrayind_t ind;
char *value;
int flags;
{
SHELL_VAR *dentry;
char *newval;
/* If we're appending, we need the old value of the array reference, so
fake out make_variable_value with a dummy SHELL_VAR */
if (flags & ASS_APPEND)
{
dentry = (SHELL_VAR *)xmalloc (sizeof (SHELL_VAR));
dentry->name = savestring (entry->name);
newval = array_reference (array_cell (entry), ind);
if (newval)
dentry->value = savestring (newval);
else
{
dentry->value = (char *)xmalloc (1);
dentry->value[0] = '\0';
}
dentry->exportstr = 0;
dentry->attributes = entry->attributes & ~(att_array|att_exported);
/* Leave the rest of the members uninitialized; the code doesn't look
at them. */
newval = make_variable_value (dentry, value, flags);
dispose_variable (dentry);
}
else
newval = make_variable_value (entry, value, flags);
if (entry->assign_func)
(*entry->assign_func) (entry, newval, ind);
else
array_insert (array_cell (entry), ind, newval);
FREE (newval);
return (entry);
}
/* Perform an array assignment name[ind]=value. If NAME already exists and
is not an array, and IND is 0, perform name=value instead. If NAME exists
and is not an array, and IND is not 0, convert it into an array with the
@ -87,13 +135,13 @@ convert_var_to_array (var)
If NAME does not exist, just create an array variable, no matter what
IND's value may be. */
SHELL_VAR *
bind_array_variable (name, ind, value)
bind_array_variable (name, ind, value, flags)
char *name;
arrayind_t ind;
char *value;
int flags;
{
SHELL_VAR *entry;
char *newval;
entry = var_lookup (name, shell_variables);
@ -109,21 +157,15 @@ bind_array_variable (name, ind, value)
entry = convert_var_to_array (entry);
/* ENTRY is an array variable, and ARRAY points to the value. */
newval = make_variable_value (entry, value);
if (entry->assign_func)
(*entry->assign_func) (entry, newval, ind);
else
array_insert (array_cell (entry), ind, newval);
FREE (newval);
return (entry);
return (bind_array_var_internal (entry, ind, value, flags));
}
/* Parse NAME, a lhs of an assignment statement of the form v[s], and
assign VALUE to that array element by calling bind_array_variable(). */
SHELL_VAR *
assign_array_element (name, value)
assign_array_element (name, value, flags)
char *name, *value;
int flags;
{
char *sub, *vname;
arrayind_t ind;
@ -150,7 +192,7 @@ assign_array_element (name, value)
return ((SHELL_VAR *)NULL);
}
entry = bind_array_variable (vname, ind, value);
entry = bind_array_variable (vname, ind, value, flags);
free (vname);
return (entry);
@ -187,8 +229,9 @@ find_or_make_array_variable (name, check_flags)
/* Perform a compound assignment statement for array NAME, where VALUE is
the text between the parens: NAME=( VALUE ) */
SHELL_VAR *
assign_array_from_string (name, value)
assign_array_from_string (name, value, flags)
char *name, *value;
int flags;
{
SHELL_VAR *var;
@ -196,21 +239,25 @@ assign_array_from_string (name, value)
if (var == 0)
return ((SHELL_VAR *)NULL);
return (assign_array_var_from_string (var, value));
return (assign_array_var_from_string (var, value, flags));
}
/* Sequentially assign the indices of indexed array variable VAR from the
words in LIST. */
SHELL_VAR *
assign_array_var_from_word_list (var, list)
assign_array_var_from_word_list (var, list, flags)
SHELL_VAR *var;
WORD_LIST *list;
int flags;
{
register arrayind_t i;
register WORD_LIST *l;
ARRAY *a;
for (a = array_cell (var), l = list, i = 0; l; l = l->next, i++)
a = array_cell (var);
i = (flags & ASS_APPEND) ? array_max_index (a) + 1 : 0;
for (l = list; l; l = l->next, i++)
if (var->assign_func)
(*var->assign_func) (var, l->word->word, i);
else
@ -221,9 +268,10 @@ assign_array_var_from_word_list (var, list)
/* Perform a compound array assignment: VAR->name=( VALUE ). The
VALUE has already had the parentheses stripped. */
SHELL_VAR *
assign_array_var_from_string (var, value)
assign_array_var_from_string (var, value, flags)
SHELL_VAR *var;
char *value;
int flags;
{
ARRAY *a;
WORD_LIST *list, *nlist;
@ -271,10 +319,11 @@ assign_array_var_from_string (var, value)
/* Now that we are ready to assign values to the array, kill the existing
value. */
if (a)
if (a && (flags & ASS_APPEND) == 0)
array_flush (a);
last_ind = (flags & ASS_APPEND) ? array_max_index (a) + 1 : 0;
for (last_ind = 0, list = nlist; list; list = list->next)
for (list = nlist; list; list = list->next)
{
w = list->word->word;
@ -283,9 +332,14 @@ assign_array_var_from_string (var, value)
{
len = skipsubscript (w, 0);
#if 1
/* XXX - changes for `+=' */
if (w[len] != ']' || (w[len+1] != '=' && (w[len+1] != '+' || w[len+2] != '=')))
#else
if (w[len] != ']' || w[len+1] != '=')
#endif
{
nval = make_variable_value (var, w);
nval = make_variable_value (var, w, flags);
if (var->assign_func)
(*var->assign_func) (var, nval, last_ind);
else
@ -314,7 +368,14 @@ assign_array_var_from_string (var, value)
continue;
}
last_ind = ind;
val = w + len + 2;
/* XXX - changes for `+=' */
if (w[len + 1] == '+' && w[len + 2] == '=')
{
flags |= ASS_APPEND;
val = w + len + 3;
}
else
val = w + len + 2;
}
else /* No [ind]=value, just a stray `=' */
{
@ -324,12 +385,7 @@ assign_array_var_from_string (var, value)
if (integer_p (var))
this_command_name = (char *)NULL; /* no command name for errors */
nval = make_variable_value (var, val);
if (var->assign_func)
(*var->assign_func) (var, nval, ind);
else
array_insert (a, ind, nval);
FREE (nval);
bind_array_var_internal (var, ind, val, flags);
last_ind++;
}
@ -536,7 +592,11 @@ array_expand_index (s, len)
exp = (char *)xmalloc (len);
strncpy (exp, s, len - 1);
exp[len - 1] = '\0';
#if 0
t = expand_string_to_string (exp, 0);
#else
t = expand_string_to_string (exp, Q_DOUBLE_QUOTES);
#endif
this_command_name = (char *)NULL;
val = evalexp (t, &expok);
free (t);
@ -652,7 +712,7 @@ array_value_internal (s, quoted, allow_all, rtype)
err_badarraysub (s);
return ((char *)NULL);
}
else if (var == 0)
else if (var == 0 || value_cell (var) == 0)
return ((char *)NULL);
else if (array_p (var) == 0)
l = add_string_to_list (value_cell (var), (WORD_LIST *)NULL);

View file

@ -1,6 +1,6 @@
/* arrayfunc.h -- declarations for miscellaneous array functions in arrayfunc.c */
/* Copyright (C) 2001 Free Software Foundation, Inc.
/* Copyright (C) 2001-2004 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@ -27,14 +27,14 @@
extern SHELL_VAR *convert_var_to_array __P((SHELL_VAR *));
extern SHELL_VAR *bind_array_variable __P((char *, arrayind_t, char *));
extern SHELL_VAR *assign_array_element __P((char *, char *));
extern SHELL_VAR *bind_array_variable __P((char *, arrayind_t, char *, int));
extern SHELL_VAR *assign_array_element __P((char *, char *, int));
extern SHELL_VAR *find_or_make_array_variable __P((char *, int));
extern SHELL_VAR *assign_array_from_string __P((char *, char *));
extern SHELL_VAR *assign_array_var_from_word_list __P((SHELL_VAR *, WORD_LIST *));
extern SHELL_VAR *assign_array_var_from_string __P((SHELL_VAR *, char *));
extern SHELL_VAR *assign_array_from_string __P((char *, char *, int));
extern SHELL_VAR *assign_array_var_from_word_list __P((SHELL_VAR *, WORD_LIST *, int));
extern SHELL_VAR *assign_array_var_from_string __P((SHELL_VAR *, char *, int));
extern int unbind_array_element __P((SHELL_VAR *, char *));
extern int skipsubscript __P((const char *, int));

View file

@ -156,6 +156,10 @@ int history_control;
to a previous entry as part of command-oriented-history processing. */
int hist_last_line_added;
/* Set to 1 if builtins/history.def:push_history added the last history
entry. */
int hist_last_line_pushed;
#if defined (READLINE)
/* If non-zero, and readline is being used, the user is offered the
chance to re-edit a failed history expansion. */
@ -217,7 +221,9 @@ bash_initialize_history ()
history_quotes_inhibit_expansion = 1;
history_search_delimiter_chars = ";&()|<>";
history_inhibit_expansion_function = bash_history_inhibit_expansion;
#if defined (BANG_HISTORY)
sv_histchars ("histchars");
#endif
}
void
@ -698,6 +704,7 @@ really_add_history (line)
char *line;
{
hist_last_line_added = 1;
hist_last_line_pushed = 0;
add_history (line);
history_lines_this_session++;
}
@ -706,7 +713,7 @@ int
history_number ()
{
using_history ();
return (get_string_value ("HISTSIZE") ? history_base + where_history () : 1);
return (remember_on_history ? history_base + where_history () : 1);
}
static int

View file

@ -38,6 +38,7 @@ extern int history_control;
extern int command_oriented_history;
extern int current_command_first_line_saved;
extern int hist_last_line_added;
extern int hist_last_line_pushed;
# if defined (BANG_HISTORY)
extern int history_expansion_inhibited;

View file

@ -1,6 +1,6 @@
/* bashline.c -- Bash's interface to the readline library. */
/* Copyright (C) 1987-2004 Free Software Foundation, Inc.
/* Copyright (C) 1987-2005 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@ -100,7 +100,7 @@ static int history_and_alias_expand_line __P((int, int));
#endif
/* Helper functions for Readline. */
static int bash_directory_expansion __P((char **));
static void bash_directory_expansion __P((char **));
static int bash_directory_completion_hook __P((char **));
static int filename_completion_ignore __P((char **));
static int bash_push_line __P((void));
@ -226,6 +226,8 @@ static char *bash_nohostname_word_break_characters = " \t\n\"'><=;|&(:";
static rl_hook_func_t *old_rl_startup_hook = (rl_hook_func_t *)NULL;
static int dot_in_path = 0;
/* What kind of quoting is performed by bash_quote_filename:
COMPLETE_DQUOTE = double-quoting the filename
COMPLETE_SQUOTE = single_quoting the filename
@ -447,7 +449,11 @@ initialize_readline ()
#endif /* SPECIFIC_COMPLETION_FUNCTIONS */
rl_bind_key_if_unbound_in_map (TAB, dynamic_complete_history, emacs_meta_keymap);
kseq[0] = TAB;
kseq[1] = '\0';
func = rl_function_of_keyseq (kseq, emacs_meta_keymap, (int *)NULL);
if (func == 0 || func == rl_tab_insert)
rl_bind_key_in_map (TAB, dynamic_complete_history, emacs_meta_keymap);
/* Tell the completer that we want a crack first. */
rl_attempted_completion_function = attempt_shell_completion;
@ -796,6 +802,7 @@ operate_and_get_next (count, c)
#define VI_EDIT_COMMAND "fc -e \"${VISUAL:-${EDITOR:-vi}}\""
#define EMACS_EDIT_COMMAND "fc -e \"${VISUAL:-${EDITOR:-emacs}}\""
#define POSIX_VI_EDIT_COMMAND "fc -e vi"
static int
edit_and_execute_command (count, c, editing_mode, edit_command)
@ -855,7 +862,10 @@ static int
vi_edit_and_execute_command (count, c)
int count, c;
{
return (edit_and_execute_command (count, c, VI_EDITING_MODE, VI_EDIT_COMMAND));
if (posixly_correct)
return (edit_and_execute_command (count, c, VI_EDITING_MODE, POSIX_VI_EDIT_COMMAND));
else
return (edit_and_execute_command (count, c, VI_EDITING_MODE, VI_EDIT_COMMAND));
}
#endif /* VI_MODE */
@ -1071,7 +1081,7 @@ attempt_shell_completion (text, start, end)
s = find_cmd_start (start);
e = find_cmd_end (end);
n = find_cmd_name (s);
if (e > s)
if (e > s && assignment (n, 0) == 0)
prog_complete_matches = programmable_completions (n, text, s, e, &foundcs);
else
foundcs = 0;
@ -1149,6 +1159,7 @@ bash_default_completion (text, start, end, qc, in_command_position)
{
#define CMD_IS_DIR(x) (absolute_pathname(x) == 0 && absolute_program(x) == 0 && *(x) != '~' && test_for_directory (x))
dot_in_path = 0;
matches = rl_completion_matches (text, command_word_completion_function);
/* If we are attempting command completion and nothing matches, we
@ -1158,27 +1169,28 @@ bash_default_completion (text, start, end, qc, in_command_position)
filenames and leave directories in the match list. */
if (matches == (char **)NULL)
rl_ignore_some_completions_function = bash_ignore_filenames;
#if 0
else if (matches[1] == 0 && CMD_IS_DIR(matches[0]))
/* Turn off rl_filename_completion_desired so readline doesn't
append a slash if there is a directory with the same name
in the current directory, or other filename-specific things.
If the name begins with a slash, we're either completing a
full pathname or a directory pathname, and readline won't be
looking in the current directory anyway, so there's no
conflict. */
rl_filename_completion_desired = 0;
else if (matches[1] == 0 && CMD_IS_DIR(matches[0]) && dot_in_path == 0)
/* If we found a single match, without looking in the current
directory (because it's not in $PATH), but the found name is
also a command in the current directory, suppress appending any
terminating character, since it's ambiguous. */
{
rl_completion_suppress_append = 1;
rl_filename_completion_desired = 0;
}
else if (matches[0] && matches[1] && STREQ (matches[0], matches[1]) && CMD_IS_DIR (matches[0]))
/* There are multiple instances of the same match (duplicate
completions haven't yet been removed). In this case, all of
the matches will be the same, and the duplicate removal code
will distill them all down to one. We turn off
rl_filename_completion_desired for the same reason as above.
will distill them all down to one. We turn on
rl_completion_suppress_append for the same reason as above.
Remember: we only care if there's eventually a single unique
completion. If there are multiple completions this won't
make a difference and the problem won't occur. */
rl_filename_completion_desired = 0;
#endif
{
rl_completion_suppress_append = 1;
rl_filename_completion_desired = 0;
}
}
}
@ -1212,23 +1224,30 @@ command_word_completion_function (hint_text, state)
static char *path = (char *)NULL;
static char *val = (char *)NULL;
static char *filename_hint = (char *)NULL;
static int path_index, hint_len, istate;
static char *dequoted_hint = (char *)NULL;
static int path_index, hint_len, dequoted_len, istate, igncase;
static int mapping_over, local_index;
static SHELL_VAR **varlist = (SHELL_VAR **)NULL;
#if defined (ALIAS)
static alias_t **alias_list = (alias_t **)NULL;
#endif /* ALIAS */
char *temp;
/* We have to map over the possibilities for command words. If we have
no state, then make one just for that purpose. */
if (!state)
{
if (dequoted_hint && dequoted_hint != hint)
free (dequoted_hint);
if (hint)
free (hint);
mapping_over = 0;
val = (char *)NULL;
temp = rl_variable_value ("completion-ignore-case");
igncase = strcmp (temp, "on") == 0;
/* If this is an absolute program name, do not check it against
aliases, reserved words, functions or builtins. We must check
whether or not it is unique, and, if so, whether that filename
@ -1241,10 +1260,24 @@ command_word_completion_function (hint_text, state)
hint = bash_tilde_expand (hint_text, 0);
else
hint = savestring (hint_text);
hint_len = strlen (hint);
dequoted_hint = hint;
/* If readline's completer found a quote character somewhere, but
didn't set the quote character, there must have been a quote
character embedded in the filename. It can't be at the start of
the filename, so we need to dequote the filename before we look
in the file system for it. */
if (rl_completion_found_quote && rl_completion_quote_character == 0)
{
dequoted_hint = bash_dequote_filename (hint, 0);
free (hint);
hint = dequoted_hint;
}
dequoted_len = hint_len = strlen (hint);
if (filename_hint)
free (filename_hint);
filename_hint = savestring (hint);
mapping_over = 4;
@ -1252,11 +1285,17 @@ command_word_completion_function (hint_text, state)
goto inner;
}
hint = savestring (hint_text);
hint_len = strlen (hint);
dequoted_hint = hint = savestring (hint_text);
dequoted_len = hint_len = strlen (hint);
if (rl_completion_found_quote && rl_completion_quote_character == 0)
{
dequoted_hint = bash_dequote_filename (hint, 0);
dequoted_len = strlen (dequoted_hint);
}
path = get_string_value ("PATH");
path_index = 0;
path_index = dot_in_path = 0;
/* Initialize the variables for each type of command word. */
local_index = 0;
@ -1374,11 +1413,13 @@ command_word_completion_function (hint_text, state)
current_path = t;
}
if (current_path[0] == '.' && current_path[1] == '\0')
dot_in_path = 1;
if (filename_hint)
free (filename_hint);
filename_hint = sh_makepath (current_path, hint, 0);
free (current_path);
}
@ -1402,7 +1443,11 @@ command_word_completion_function (hint_text, state)
if (absolute_program (hint))
{
match = strncmp (val, hint, hint_len) == 0;
if (igncase == 0)
match = strncmp (val, hint, hint_len) == 0;
else
match = strncasecmp (val, hint, hint_len) == 0;
/* If we performed tilde expansion, restore the original
filename. */
if (*hint_text == '~')
@ -1435,7 +1480,10 @@ command_word_completion_function (hint_text, state)
if (temp)
{
temp++;
freetemp = match = strncmp (temp, hint, hint_len) == 0;
if (igncase == 0)
freetemp = match = strncmp (temp, hint, hint_len) == 0;
else
freetemp = match = strncasecmp (temp, hint, hint_len) == 0;
if (match)
temp = savestring (temp);
}
@ -1514,6 +1562,13 @@ command_subst_completion_function (text, state)
/* If there is more than one match, rl_completion_matches has already
put the lcd in matches[0]. Skip over it. */
cmd_index = matches && matches[0] && matches[1];
/* If there's a single match and it's a directory, set the append char
to the expected `/'. Otherwise, don't append anything. */
if (matches && matches[0] && matches[1] == 0 && test_for_directory (matches[0]))
rl_completion_append_character = '/';
else
rl_completion_suppress_append = 1;
}
if (!matches || !matches[cmd_index])
@ -1898,7 +1953,7 @@ tcsh_magic_space (count, ignore)
else
return (1);
}
#endif
#endif /* BANG_HISTORY */
/* History and alias expand the line. */
static int
@ -1907,7 +1962,10 @@ history_and_alias_expand_line (count, ignore)
{
char *new_line;
new_line = 0;
#if defined (BANG_HISTORY)
new_line = history_expand_line_internal (rl_line_buffer);
#endif
#if defined (ALIAS)
if (new_line)
@ -1943,7 +2001,10 @@ shell_expand_line (count, ignore)
char *new_line;
WORD_LIST *expanded_string;
new_line = 0;
#if defined (BANG_HISTORY)
new_line = history_expand_line_internal (rl_line_buffer);
#endif
#if defined (ALIAS)
if (new_line)
@ -2200,7 +2261,7 @@ bash_ignore_everything (names)
/* Simulate the expansions that will be performed by
rl_filename_completion_function. This must be called with the address of
a pointer to malloc'd memory. */
static int
static void
bash_directory_expansion (dirname)
char **dirname;
{
@ -2296,9 +2357,12 @@ bash_directory_completion_hook (dirname)
if (temp1[len1 - 1] == '/')
{
len2 = strlen (temp2);
temp2 = (char *)xrealloc (temp2, len2 + 2);
temp2[len2] = '/';
temp2[len2 + 1] = '\0';
if (len2 > 2) /* don't append `/' to `/' or `//' */
{
temp2 = (char *)xrealloc (temp2, len2 + 2);
temp2[len2] = '/';
temp2[len2 + 1] = '\0';
}
}
free (local_dirname);
*dirname = temp2;
@ -2815,10 +2879,6 @@ bash_quote_filename (s, rtype, qcp)
to perform tilde expansion, because single and double
quotes inhibit tilde expansion by the shell. */
mtext = s;
if (mtext[0] == '~' && rtype == SINGLE_MATCH)
mtext = bash_tilde_expand (s, 0);
cs = completion_quoting_style;
/* Might need to modify the default completion style based on *qcp,
since it's set to any user-provided opening quote. We also change
@ -2826,7 +2886,7 @@ bash_quote_filename (s, rtype, qcp)
the word being completed contains newlines, since those are not
quoted correctly using backslashes (a backslash-newline pair is
special to the shell parser). */
if (*qcp == '\0' && cs == COMPLETE_BSQUOTE && xstrchr (mtext, '\n'))
if (*qcp == '\0' && cs == COMPLETE_BSQUOTE && xstrchr (s, '\n'))
cs = COMPLETE_SQUOTE;
else if (*qcp == '"')
cs = COMPLETE_DQUOTE;
@ -2834,17 +2894,23 @@ bash_quote_filename (s, rtype, qcp)
cs = COMPLETE_SQUOTE;
#if defined (BANG_HISTORY)
else if (*qcp == '\0' && history_expansion && cs == COMPLETE_DQUOTE &&
history_expansion_inhibited == 0 && xstrchr (mtext, '!'))
history_expansion_inhibited == 0 && xstrchr (s, '!'))
cs = COMPLETE_BSQUOTE;
if (*qcp == '"' && history_expansion && cs == COMPLETE_DQUOTE &&
history_expansion_inhibited == 0 && xstrchr (mtext, '!'))
history_expansion_inhibited == 0 && xstrchr (s, '!'))
{
cs = COMPLETE_BSQUOTE;
*qcp = '\0';
}
#endif
/* Don't tilde-expand backslash-quoted filenames, since only single and
double quotes inhibit tilde expansion. */
mtext = s;
if (mtext[0] == '~' && rtype == SINGLE_MATCH && cs != COMPLETE_BSQUOTE)
mtext = bash_tilde_expand (s, 0);
switch (cs)
{
case COMPLETE_DQUOTE:

View file

@ -41,6 +41,8 @@
#define SPECIAL_BUILTIN 0x8 /* This is a Posix `special' builtin. */
#define ASSIGNMENT_BUILTIN 0x10 /* This builtin takes assignment statements. */
#define BASE_INDENT 4
/* The thing that we build the array of builtins out of. */
struct builtin {
char *name; /* The name that the user types. */

View file

@ -1,6 +1,6 @@
# This Makefile for building libbuiltins.a is in -*- text -*- for Emacs.
#
# Copyright (C) 1996-2003 Free Software Foundation, Inc.
# Copyright (C) 1996-2005 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
@ -54,7 +54,7 @@ LIBBUILD = ${BUILD_DIR}/lib
PROFILE_FLAGS = @PROFILE_FLAGS@
CFLAGS = @CFLAGS@
CFLAGS_FOR_BUILD = @CFLAGS_FOR_BUILD@
CFLAGS_FOR_BUILD = @CFLAGS_FOR_BUILD@ @CROSS_COMPILE@
CPPFLAGS = @CPPFLAGS@
CPPFLAGS_FOR_BUILD = @CPPFLAGS_FOR_BUILD@
LOCAL_CFLAGS = @LOCAL_CFLAGS@ ${DEBUG}
@ -96,6 +96,7 @@ GCC_LINT_FLAGS = -Wall -Wshadow -Wpointer-arith -Wcast-qual \
MKBUILTINS = mkbuiltins$(EXEEXT)
DIRECTDEFINE = -D $(srcdir)
HELPDIRDEFINE = @HELPDIRDEFINE@
HELPSTRINGS = @HELPSTRINGS@
# xxx this is bad style
RL_LIBSRC = $(topdir)/lib/readline
@ -160,7 +161,7 @@ builtext.h builtins.c: $(MKBUILTINS) $(DEFSRC)
@-if test -f builtins.c; then mv -f builtins.c old-builtins.c; fi
@-if test -f builtext.h; then mv -f builtext.h old-builtext.h; fi
./$(MKBUILTINS) -externfile builtext.h -structfile builtins.c \
-noproduction $(DIRECTDEFINE) $(HELPDIRDEFINE) $(DEFSRC)
-noproduction $(DIRECTDEFINE) $(HELPDIRDEFINE) $(HELPSTRINGS) $(DEFSRC)
@-if cmp -s old-builtext.h builtext.h 2>/dev/null; then \
mv old-builtext.h builtext.h; \
else \
@ -178,8 +179,7 @@ helpdoc: $(MKBUILTINS) $(DEFSRC)
install-help:
@-if test -n "${HELPDIR}" && test -d helpfiles ; then \
test -d ${HELPDIR} || ${SHELL} ${MKDIRS} $(DESTDIR)$(HELPDIR) ;\
( cd helpfiles ; \
for f in *; do \
( for f in helpfiles/*; do \
echo installing $$f; \
${INSTALL_DATA} $$f $(DESTDIR)$(HELPDIR); \
done; ) ; \
@ -404,12 +404,12 @@ exec.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h
exec.o: $(topdir)/subst.h $(topdir)/externs.h $(topdir)/flags.h
exec.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
exec.o: $(srcdir)/common.h $(topdir)/execute_cmd.h $(BASHINCDIR)/maxpath.h
exec.o: $(topdir)/findcmd.h
exec.o: $(topdir)/findcmd.h $(topdir)/jobs.h
exit.o: $(topdir)/bashtypes.h
exit.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h
exit.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h
exit.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h
exit.o: $(topdir)/subst.h $(topdir)/externs.h
exit.o: $(topdir)/subst.h $(topdir)/externs.h $(topdir)/jobs.h
exit.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
exit.o: $(BASHINCDIR)/maxpath.h ./builtext.h
fc.o: $(topdir)/bashtypes.h $(BASHINCDIR)/posixstat.h
@ -427,6 +427,7 @@ fg_bg.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h
fg_bg.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h
fg_bg.o: $(topdir)/subst.h $(topdir)/externs.h $(BASHINCDIR)/maxpath.h
fg_bg.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
fg_bg.o: $(topdir)/jobs.h
getopts.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h
getopts.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h
getopts.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h
@ -458,7 +459,7 @@ inlib.o: $(BASHINCDIR)/maxpath.h $(topdir)/subst.h $(topdir)/externs.h
inlib.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h
jobs.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h $(topdir)/error.h
jobs.o: $(topdir)/general.h $(topdir)/xmalloc.h $(topdir)/quit.h $(srcdir)/bashgetopt.h
jobs.o: $(BASHINCDIR)/maxpath.h $(topdir)/externs.h
jobs.o: $(BASHINCDIR)/maxpath.h $(topdir)/externs.h $(topdir)/jobs.h
jobs.o: $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h $(topdir)/subst.h
jobs.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
kill.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h $(topdir)/error.h
@ -466,6 +467,7 @@ kill.o: $(topdir)/general.h $(topdir)/xmalloc.h $(topdir)/subst.h $(topdir)/exte
kill.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h
kill.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/trap.h $(topdir)/unwind_prot.h
kill.o: $(topdir)/variables.h $(topdir)/conftypes.h $(BASHINCDIR)/maxpath.h
kill.o: $(topdir)/jobs.h
let.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h
let.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h
let.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h
@ -525,6 +527,7 @@ suspend.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h
suspend.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h
suspend.o: $(topdir)/subst.h $(topdir)/externs.h $(BASHINCDIR)/maxpath.h
suspend.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
suspend.o: $(topdir)/jobs.h
test.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h
test.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h
test.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h
@ -565,6 +568,7 @@ wait.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h
wait.o: $(topdir)/quit.h $(topdir)/dispose_cmd.h $(topdir)/make_cmd.h
wait.o: $(topdir)/subst.h $(topdir)/externs.h $(BASHINCDIR)/maxpath.h
wait.o: $(topdir)/shell.h $(topdir)/syntax.h $(topdir)/unwind_prot.h $(topdir)/variables.h $(topdir)/conftypes.h
wait.o: $(topdir)/jobs.h
wait.o: $(BASHINCDIR)/chartypes.h
shopt.o: $(topdir)/command.h ../config.h $(BASHINCDIR)/memalloc.h
shopt.o: $(topdir)/error.h $(topdir)/general.h $(topdir)/xmalloc.h

View file

@ -55,6 +55,7 @@ $END
#include "../shell.h"
#include "common.h"
#include "builtext.h"
#include "bashgetopt.h"
#ifdef LOADABLE_BUILTIN
# include "builtins.h"
@ -88,6 +89,10 @@ caller_builtin (list)
if (bash_source_a == 0 || array_empty (bash_source_a))
return (EXECUTION_FAILURE);
if (no_options (list))
return (EX_USAGE);
list = loptend; /* skip over possible `--' */
/* If there is no argument list, then give short form: line filename. */
if (list == 0)
{
@ -125,11 +130,11 @@ caller_builtin (list)
#ifdef LOADABLE_BUILTIN
static char *caller_doc[] = {
N_("Returns the context of the current subroutine call."),
N_(""),
N_(" "),
N_("Without EXPR, returns returns \"$line $filename\". With EXPR,"),
N_("returns \"$line $subroutine $filename\"; this extra information"),
N_("can be used used to provide a stack trace."),
N_(""),
N_(" "),
N_("The value of EXPR indicates how many call frames to go back before the"),
N_("current one; the top frame is frame 0."),
(char *)NULL

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-2003 Free Software Foundation, Inc.
Copyright (C) 1987-2005 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@ -59,6 +59,7 @@ extern int array_needs_making;
extern char *bash_getcwd_errstr;
static int bindpwd __P((int));
static void setpwd __P((char *));
static int change_to_directory __P((char *, int));
static char *cdspell __P((char *));
@ -84,6 +85,23 @@ instead of following symbolic links; the -L option forces symbolic links
to be followed.
$END
/* Just set $PWD, don't change OLDPWD. Used by `pwd -P' in posix mode. */
static void
setpwd (dirname)
char *dirname;
{
int old_anm;
SHELL_VAR *tvar;
old_anm = array_needs_making;
tvar = bind_variable ("PWD", dirname ? dirname : "", 0);
if (old_anm == 0 && array_needs_making && exported_p (tvar))
{
update_export_env_inplace ("PWD=", 4, dirname ? dirname : "");
array_needs_making = 0;
}
}
static int
bindpwd (no_symlinks)
int no_symlinks;
@ -100,19 +118,14 @@ bindpwd (no_symlinks)
old_anm = array_needs_making;
pwdvar = get_string_value ("PWD");
tvar = bind_variable ("OLDPWD", pwdvar);
tvar = bind_variable ("OLDPWD", pwdvar, 0);
if (old_anm == 0 && array_needs_making && exported_p (tvar))
{
update_export_env_inplace ("OLDPWD=", 7, pwdvar);
array_needs_making = 0;
}
tvar = bind_variable ("PWD", dirname ? dirname : "");
if (old_anm == 0 && array_needs_making && exported_p (tvar))
{
update_export_env_inplace ("PWD=", 4, dirname ? dirname : "");
array_needs_making = 0;
}
setpwd (dirname);
if (dirname && dirname != the_current_working_directory)
free (dirname);
@ -233,9 +246,13 @@ cd_builtin (list)
printf ("%s\n", path);
free (temp);
#if 0
/* Posix.2 says that after using CDPATH, the resultant
value of $PWD will not contain `.' or `..'. */
return (bindpwd (posixly_correct || no_symlinks));
#else
return (bindpwd (no_symlinks));
#endif
}
else
free (temp);
@ -298,7 +315,7 @@ cd_builtin (list)
$BUILTIN pwd
$FUNCTION pwd_builtin
$SHORT_DOC pwd [-PL]
$SHORT_DOC pwd [-LP]
Print the current working directory. With the -P option, pwd prints
the physical directory, without any symbolic links; the -L option
makes pwd follow symbolic links.
@ -314,16 +331,17 @@ pwd_builtin (list)
WORD_LIST *list;
{
char *directory;
int opt;
int opt, pflag;
verbatim_pwd = no_symbolic_links;
pflag = 0;
reset_internal_getopt ();
while ((opt = internal_getopt (list, "LP")) != -1)
{
switch (opt)
{
case 'P':
verbatim_pwd = 1;
verbatim_pwd = pflag = 1;
break;
case 'L':
verbatim_pwd = 0;
@ -342,7 +360,8 @@ pwd_builtin (list)
/* Try again using getcwd() if canonicalization fails (for instance, if
the file system has changed state underneath bash). */
if (tcwd && directory == 0)
if ((tcwd && directory == 0) ||
(posixly_correct && same_file (".", tcwd, (struct stat *)0, (struct stat *)0) == 0))
directory = resetpwd ("pwd");
#undef tcwd
@ -350,12 +369,15 @@ pwd_builtin (list)
if (directory)
{
printf ("%s\n", directory);
/* This is dumb but posix-mandated. */
if (posixly_correct && pflag)
setpwd (directory);
if (directory != the_current_working_directory)
free (directory);
fflush (stdout);
if (ferror (stdout))
{
builtin_error (_("write error: %s"), strerror (errno));
sh_wrerror ();
clearerr (stdout);
return (EXECUTION_FAILURE);
}
@ -378,7 +400,7 @@ change_to_directory (newdir, nolinks)
int nolinks;
{
char *t, *tdir;
int err, canon_failed, r;
int err, canon_failed, r, ndlen, dlen;
tdir = (char *)NULL;
@ -396,6 +418,9 @@ change_to_directory (newdir, nolinks)
tdir = nolinks ? sh_physpath (t, 0)
: sh_canonpath (t, PATH_CHECKDOTDOT|PATH_CHECKEXISTS);
ndlen = strlen (newdir);
dlen = strlen (t);
/* Use the canonicalized version of NEWDIR, or, if canonicalization
failed, use the non-canonical form. */
canon_failed = 0;
@ -411,7 +436,7 @@ change_to_directory (newdir, nolinks)
/* In POSIX mode, if we're resolving symlinks logically and sh_canonpath
returns NULL (because it checks the path, it will return NULL if the
resolved path doesn't exist), fail immediately. */
if (posixly_correct && nolinks == 0 && canon_failed)
if (posixly_correct && nolinks == 0 && canon_failed && (errno != ENAMETOOLONG || ndlen > PATH_MAX))
{
#if defined ENAMETOOLONG
if (errno != ENOENT && errno != ENAMETOOLONG)
@ -419,6 +444,7 @@ change_to_directory (newdir, nolinks)
if (errno != ENOENT)
#endif
errno = ENOTDIR;
free (tdir);
return (0);
}
@ -436,13 +462,17 @@ change_to_directory (newdir, nolinks)
else
set_working_directory (tdir);
free (tdir);
return (1);
}
/* We failed to change to the appropriate directory name. If we tried
what the user passed (nolinks != 0), punt now. */
if (nolinks)
return (0);
{
free (tdir);
return (0);
}
err = errno;

View file

@ -1,7 +1,7 @@
This file is command.def, from which is created command.c.
It implements the builtin "command" in Bash.
Copyright (C) 1987-2002 Free Software Foundation, Inc.
Copyright (C) 1987-2004 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@ -78,7 +78,7 @@ command_builtin (list)
use_standard_path = 1;
break;
case 'V':
verbose = CDESC_SHORTDESC; /* look in common.h for constants */
verbose = CDESC_SHORTDESC|CDESC_ABSPATH; /* look in common.h for constants */
break;
case 'v':
verbose = CDESC_REUSABLE; /* ditto */
@ -101,7 +101,7 @@ command_builtin (list)
{
found = describe_command (list->word->word, verbose);
if (found == 0)
if (found == 0 && verbose != CDESC_REUSABLE)
sh_notfound (list->word->word);
any_found += found;
@ -131,7 +131,7 @@ command_builtin (list)
add_unwind_protect ((Function *)restore_path, old_path);
standard_path = get_standard_path ();
bind_variable ("PATH", standard_path ? standard_path : "");
bind_variable ("PATH", standard_path ? standard_path : "", 0);
FREE (standard_path);
}
@ -170,7 +170,7 @@ restore_path (var)
{
if (var)
{
bind_variable ("PATH", var);
bind_variable ("PATH", var, 0);
free (var);
}
else

View file

@ -1,4 +1,4 @@
/* Copyright (C) 1987-2004 Free Software Foundation, Inc.
/* Copyright (C) 1987-2005 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@ -270,6 +270,12 @@ sh_notbuiltin (s)
builtin_error (_("%s: not a shell builtin"), s);
}
void
sh_wrerror ()
{
builtin_error (_("write error: %s"), strerror (errno));
}
/* **************************************************************** */
/* */
/* Shell positional parameter manipulation */
@ -508,15 +514,17 @@ get_job_by_name (name, flags)
{
register int i, wl, cl, match, job;
register PROCESS *p;
register JOB *j;
job = NO_JOB;
wl = strlen (name);
for (i = job_slots - 1; i >= 0; i--)
for (i = js.j_jobslots - 1; i >= 0; i--)
{
if (jobs[i] == 0 || ((flags & JM_STOPPED) && JOBSTATE(i) != JSTOPPED))
j = get_job_by_jid (i);
if (j == 0 || ((flags & JM_STOPPED) && J_JOBSTATE(j) != JSTOPPED))
continue;
p = jobs[i]->pipe;
p = j->pipe;
do
{
if (flags & JM_EXACT)
@ -547,7 +555,7 @@ get_job_by_name (name, flags)
else
job = i;
}
while (p != jobs[i]->pipe);
while (p != j->pipe);
}
return (job);
@ -562,7 +570,7 @@ get_job_spec (list)
int job, jflags;
if (list == 0)
return (current_job);
return (js.j_current);
word = list->word->word;
@ -575,20 +583,19 @@ get_job_spec (list)
if (DIGIT (*word) && all_digits (word))
{
job = atoi (word);
return (job > job_slots ? NO_JOB : job - 1);
return (job > js.j_jobslots ? NO_JOB : job - 1);
}
jflags = 0;
switch (*word)
{
case 0:
return NO_JOB;
case '%':
case '+':
return (current_job);
return (js.j_current);
case '-':
return (previous_job);
return (js.j_previous);
case '?': /* Substring search requested. */
jflags |= JM_SUBSTRING;

View file

@ -40,6 +40,7 @@
#define CDESC_PATH_ONLY 0x010 /* type -p */
#define CDESC_FORCE_PATH 0x020 /* type -ap or type -P */
#define CDESC_NOFUNCS 0x040 /* type -f */
#define CDESC_ABSPATH 0x080 /* convert to absolute path, no ./ */
/* Flags for get_job_by_name */
#define JM_PREFIX 0x01 /* prefix of job name */
@ -76,6 +77,7 @@ extern void sh_readonly __P((const char *));
extern void sh_nojobs __P((char *));
extern void sh_restricted __P((char *));
extern void sh_notbuiltin __P((char *));
extern void sh_wrerror __P((void));
extern char **make_builtin_argv __P((WORD_LIST *, int *));
extern void remember_args __P((WORD_LIST *, int));

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-2003 Free Software Foundation, Inc.
Copyright (C) 1987-2004 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@ -222,18 +222,24 @@ declare_internal (list, local_var)
while (list) /* declare [-afFirx] name [name ...] */
{
char *value, *name;
int offset;
int offset, aflags;
#if defined (ARRAY_VARS)
int making_array_special, compound_array_assign, simple_array_assign;
#endif
name = savestring (list->word->word);
offset = assignment (name, 0);
aflags = 0;
if (offset) /* declare [-afFirx] name=value */
{
name[offset] = '\0';
value = name + offset + 1;
if (name[offset - 1] == '+')
{
aflags |= ASS_APPEND;
name[offset - 1] = '\0';
}
}
else
value = "";
@ -353,7 +359,7 @@ declare_internal (list, local_var)
var = make_new_array_variable (name);
else
#endif
var = bind_variable (name, "");
var = bind_variable (name, "", 0);
}
/* Cannot use declare +r to turn off readonly attribute. */
@ -377,7 +383,13 @@ declare_internal (list, local_var)
#if defined (ARRAY_VARS)
if ((making_array_special || (flags_on & att_array) || array_p (var)) && offset)
{
int vlen;
vlen = STRLEN (value);
#if 0
if (value[0] == '(' && strchr (value, ')'))
#else
if (value[0] == '(' && value[vlen-1] == ')')
#endif
compound_array_assign = 1;
else
simple_array_assign = 1;
@ -401,23 +413,23 @@ declare_internal (list, local_var)
#if defined (ARRAY_VARS)
if (offset && compound_array_assign)
assign_array_var_from_string (var, value);
assign_array_var_from_string (var, value, aflags);
else if (simple_array_assign && subscript_start)
{
/* declare [-a] name[N]=value */
*subscript_start = '['; /* ] */
var = assign_array_element (name, value);
var = assign_array_element (name, value, 0); /* XXX - not aflags */
*subscript_start = '\0';
}
else if (simple_array_assign)
/* let bind_array_variable take care of this. */
bind_array_variable (name, 0, value);
bind_array_variable (name, 0, value, aflags);
else
#endif
/* bind_variable_value duplicates the essential internals of
bind_variable() */
if (offset)
bind_variable_value (var, value);
bind_variable_value (var, value, aflags);
/* If we found this variable in the temporary environment, as with
`var=value declare -x var', make sure it is treated identically
@ -437,7 +449,7 @@ declare_internal (list, local_var)
if (tv)
{
tvalue = var_isset (var) ? savestring (value_cell (var)) : savestring ("");
tv = bind_variable (var->name, tvalue);
tv = bind_variable (var->name, tvalue, 0);
tv->attributes |= var->attributes & ~att_tempvar;
if (tv->context > 0)
VSETATTR (tv, att_propagate);

View file

@ -72,12 +72,14 @@ $END
existing system shells won't barf. Regrettably, the SUS v2 has
standardized the Sys V echo behavior. This variable is external
so that we can have a `shopt' variable to control it at runtime. */
#if defined (DEFAULT_ECHO_TO_XPG)
#if defined (DEFAULT_ECHO_TO_XPG) || defined (STRICT_POSIX)
int xpg_echo = 1;
#else
int xpg_echo = 0;
#endif /* DEFAULT_ECHO_TO_XPG */
extern int posixly_correct;
/* Print the words in LIST to standard output. If the first word is
`-n', then don't print a trailing newline. We also support the
echo syntax from Version 9 Unix systems. */
@ -91,6 +93,9 @@ echo_builtin (list)
do_v9 = xpg_echo;
display_return = 1;
if (posixly_correct && xpg_echo)
goto just_echo;
for (; list && (temp = list->word->word) && *temp == '-'; list = list->next)
{
/* If it appears that we are handling options, then make sure that
@ -170,6 +175,7 @@ just_echo:
fflush (stdout);
if (ferror (stdout))
{
sh_wrerror ();
clearerr (stdout);
return (EXECUTION_FAILURE);
}

View file

@ -39,6 +39,7 @@
#include "../flags.h"
#include "../input.h"
#include "../execute_cmd.h"
#include "../trap.h"
#if defined (HISTORY)
# include "../bashhist.h"
@ -82,7 +83,7 @@ _evalfile (filename, flags)
size_t file_size;
sh_vmsg_func_t *errfunc;
#if defined (ARRAY_VARS)
SHELL_VAR *funcname_v, *bash_source_v, *bash_lineno_v;
SHELL_VAR *funcname_v, *nfv, *bash_source_v, *bash_lineno_v;
ARRAY *funcname_a, *bash_source_a, *bash_lineno_a;
# if defined (DEBUGGER)
SHELL_VAR *bash_argv_v, *bash_argc_v;
@ -246,9 +247,16 @@ file_error_and_exit:
}
#if defined (ARRAY_VARS)
/* These two variables cannot be unset, and cannot be affected by the
sourced file. */
array_pop (bash_source_a);
array_pop (bash_lineno_a);
array_pop (funcname_a);
/* FUNCNAME can be unset, and so can potentially be changed by the
sourced file. */
GET_ARRAY_FROM_VAR ("FUNCNAME", nfv, funcname_a);
if (nfv == funcname_v)
array_pop (funcname_a);
# if defined (DEBUGGER)
if ((flags & FEVAL_NOPUSHARGS) == 0)
{

View file

@ -1,4 +1,6 @@
/* Copyright (C) 1996 Free Software Foundation, Inc.
/* Evaluate a string as one or more shell commands.
Copyright (C) 1996-2005 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@ -58,6 +60,7 @@ extern int indirection_level, startup_state, subshell_environment;
extern int line_number;
extern int last_command_exit_value;
extern int running_trap;
extern int loop_level;
extern int posixly_correct;
int parse_and_execute_level = 0;
@ -105,6 +108,7 @@ parse_and_execute (string, from_file, flags)
unwind_protect_jmp_buf (top_level);
unwind_protect_int (indirection_level);
unwind_protect_int (line_number);
unwind_protect_int (loop_level);
if (flags & (SEVAL_NONINT|SEVAL_INTERACT))
unwind_protect_int (interactive);
@ -231,17 +235,21 @@ parse_and_execute (string, from_file, flags)
* IF
* we were invoked as `bash -c' (startup_state == 2) AND
* parse_and_execute has not been called recursively AND
* we're not running a trap AND
* we have parsed the full command (string == '\0') AND
* we have a simple command without redirections AND
* the command is not being timed
* the command is not being timed AND
* the command's return status is not being inverted
* THEN
* tell the execution code that we don't need to fork
*/
if (startup_state == 2 && parse_and_execute_level == 1 &&
running_trap == 0 &&
*bash_input.location.string == '\0' &&
command->type == cm_simple &&
!command->redirects && !command->value.Simple->redirects &&
((command->flags & CMD_TIME_PIPELINE) == 0))
((command->flags & CMD_TIME_PIPELINE) == 0) &&
((command->flags & CMD_INVERT_RETURN) == 0))
{
command->flags |= CMD_NO_FORK;
command->value.Simple->flags |= CMD_NO_FORK;

View file

@ -221,7 +221,8 @@ failed_exec:
initialize_signals (1);
#if defined (JOB_CONTROL)
restart_job_control ();
if (interactive_shell || job_control)
restart_job_control ();
#endif /* JOB_CONTROL */
return (exit_value);

View file

@ -1,7 +1,7 @@
This file is exit.def, from which is created exit.c.
It implements the builtins "exit", and "logout" in Bash.
Copyright (C) 1987-2003 Free Software Foundation, Inc.
Copyright (C) 1987-2005 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@ -105,7 +105,7 @@ exit_or_logout (list)
if (!exit_immediate_okay)
{
register int i;
for (i = 0; i < job_slots; i++)
for (i = 0; i < js.j_jobslots; i++)
if (jobs[i] && STOPPED (i))
{
fprintf (stderr, _("There are stopped jobs.\n"));

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-2003 Free Software Foundation, Inc.
Copyright (C) 1987-2005 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@ -84,10 +84,12 @@ extern int errno;
extern int echo_input_at_read;
extern int current_command_line_count;
extern int literal_history;
extern int posixly_correct;
extern int unlink __P((const char *));
extern FILE *sh_mktmpfp __P((char *, int, char **));
extern int delete_last_history __P((void));
/* **************************************************************** */
/* */
@ -155,6 +157,11 @@ static void fc_addhist __P((char *));
/* String to execute on a file that we want to edit. */
#define FC_EDIT_COMMAND "${FCEDIT:-${EDITOR:-vi}}"
#if defined (STRICT_POSIX)
# define POSIX_FC_EDIT_COMMAND "${FCEDIT:-ed}"
#else
# define POSIX_FC_EDIT_COMMAND "${FCEDIT:-${EDITOR:-ed}}"
#endif
int
fc_builtin (list)
@ -166,7 +173,7 @@ fc_builtin (list)
int histbeg, histend, last_hist, retval, opt;
FILE *stream;
REPL *rlist, *rl;
char *ename, *command, *newcom;
char *ename, *command, *newcom, *fcedit;
HIST_ENTRY **hlist;
char *fn;
@ -284,6 +291,11 @@ fc_builtin (list)
line was actually added (HISTIGNORE may have caused it to not be),
so we check hist_last_line_added. */
/* "When not listing, he fc command that caused the editing shall not be
entered into the history list." */
if (listing == 0 && hist_last_line_added)
delete_last_history ();
last_hist = i - 1 - hist_last_line_added;
if (list)
@ -302,7 +314,7 @@ fc_builtin (list)
if (listing)
{
histend = last_hist;
histbeg = histend - 16;
histbeg = histend - 16 + 1; /* +1 because loop below uses >= */
if (histbeg < 0)
histbeg = 0;
}
@ -347,7 +359,12 @@ fc_builtin (list)
if (numbering)
fprintf (stream, "%d", i + history_base);
if (listing)
fprintf (stream, "\t%c", histdata (i) ? '*' : ' ');
{
if (posixly_correct)
fputs ("\t", stream);
else
fprintf (stream, "\t%c", histdata (i) ? '*' : ' ');
}
fprintf (stream, "%s\n", histline (i));
}
@ -364,8 +381,9 @@ fc_builtin (list)
}
else
{
command = (char *)xmalloc (3 + strlen (FC_EDIT_COMMAND) + strlen (fn));
sprintf (command, "%s %s", FC_EDIT_COMMAND, fn);
fcedit = posixly_correct ? POSIX_FC_EDIT_COMMAND : FC_EDIT_COMMAND;
command = (char *)xmalloc (3 + strlen (fcedit) + strlen (fn));
sprintf (command, "%s %s", fcedit, fn);
}
retval = parse_and_execute (command, "fc", SEVAL_NOHIST);
if (retval != EXECUTION_SUCCESS)
@ -489,7 +507,7 @@ fc_gethist (command, hlist)
{
int i;
if (!hlist)
if (hlist == 0)
return ((char *)NULL);
i = fc_gethnum (command, hlist);
@ -573,41 +591,18 @@ static void
fc_replhist (command)
char *command;
{
register int i;
HIST_ENTRY **hlist, *histent, *discard;
int n;
if (command == 0 || *command == '\0')
return;
hlist = history_list ();
if (hlist == NULL)
return;
for (i = 0; hlist[i]; i++);
i--;
/* History_get () takes a parameter that should be
offset by history_base. */
histent = history_get (history_base + i); /* Don't free this */
if (histent == NULL)
return;
n = strlen (command);
if (command[n - 1] == '\n')
command[n - 1] = '\0';
if (command && *command)
{
discard = remove_history (i);
if (discard)
{
FREE (discard->line);
free ((char *) discard);
}
delete_last_history ();
maybe_add_history (command); /* Obeys HISTCONTROL setting. */
}
}
@ -620,13 +615,16 @@ fc_addhist (line)
{
register int n;
if (line == 0 || *line == 0)
return;
n = strlen (line);
if (line[n - 1] == '\n')
line[n - 1] = '\0';
if (line && *line)
maybe_add_history (line);
maybe_add_history (line); /* Obeys HISTCONTROL setting. */
}
#endif

View file

@ -1,7 +1,7 @@
This file is fg_bg.def, from which is created fg_bg.c.
It implements the builtins "bg" and "fg" in Bash.
Copyright (C) 1987-2003 Free Software Foundation, Inc.
Copyright (C) 1987-2005 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@ -82,8 +82,8 @@ fg_builtin (list)
$BUILTIN bg
$FUNCTION bg_builtin
$DEPENDS_ON JOB_CONTROL
$SHORT_DOC bg [job_spec]
Place JOB_SPEC in the background, as if it had been started with
$SHORT_DOC bg [job_spec ...]
Place each JOB_SPEC in the background, as if it had been started with
`&'. If JOB_SPEC is not present, the shell's notion of the current
job is used.
$END
@ -94,6 +94,8 @@ int
bg_builtin (list)
WORD_LIST *list;
{
int r;
if (job_control == 0)
{
sh_nojobs ((char *)NULL);
@ -104,7 +106,19 @@ bg_builtin (list)
return (EX_USAGE);
list = loptend;
return (fg_bg (list, 0));
/* This relies on the fact that fg_bg() takes a WORD_LIST *, but only acts
on the first member (if any) of that list. */
r = EXECUTION_SUCCESS;
do
{
if (fg_bg (list, 0) == EXECUTION_FAILURE)
r = EXECUTION_FAILURE;
if (list)
list = list->next;
}
while (list);
return r;
}
/* How to put a job into the foreground/background. */
@ -115,11 +129,12 @@ fg_bg (list, foreground)
{
sigset_t set, oset;
int job, status, old_async_pid;
JOB *j;
BLOCK_CHILD (set, oset);
job = get_job_spec (list);
if (job < 0 || job >= job_slots || jobs[job] == 0)
if (INVALID_JOB (job))
{
if (job != DUP_JOB)
sh_badjob (list ? list->word->word : "current");
@ -127,7 +142,8 @@ fg_bg (list, foreground)
goto failure;
}
/* Or if jobs[job]->pgrp == shell_pgrp. */
j = get_job_by_jid (job);
/* Or if j->pgrp == shell_pgrp. */
if (IS_JOBCONTROL (job) == 0)
{
builtin_error (_("job %d started without job control"), job + 1);
@ -137,7 +153,7 @@ fg_bg (list, foreground)
if (foreground == 0)
{
old_async_pid = last_asynchronous_pid;
last_asynchronous_pid = jobs[job]->pgrp; /* As per Posix.2 5.4.2 */
last_asynchronous_pid = j->pgrp; /* As per Posix.2 5.4.2 */
}
status = start_job (job, foreground);
@ -146,7 +162,7 @@ fg_bg (list, foreground)
{
/* win: */
UNBLOCK_CHILD (oset);
return (status);
return (foreground ? status : EXECUTION_SUCCESS);
}
else
{

View file

@ -1,7 +1,7 @@
This file is getopts.def, from which is created getopts.c.
It implements the builtin "getopts" in Bash.
Copyright (C) 1987-2002 Free Software Foundation, Inc.
Copyright (C) 1987-2004 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@ -101,7 +101,7 @@ getopts_bind_variable (name, value)
if (legal_identifier (name))
{
v = bind_variable (name, value);
v = bind_variable (name, value, 0);
return (v && (readonly_p (v) == 0)) ? EXECUTION_SUCCESS : EXECUTION_FAILURE;
}
else
@ -228,7 +228,7 @@ dogetopts (argc, argv)
}
while (n /= 10);
}
bind_variable ("OPTIND", numval + i);
bind_variable ("OPTIND", numval + i, 0);
/* If an error occurred, decide which one it is and set the return
code appropriately. In all cases, the option character in error
@ -259,7 +259,7 @@ dogetopts (argc, argv)
{
strval[0] = (char)sh_optopt;
strval[1] = '\0';
bind_variable ("OPTARG", strval);
bind_variable ("OPTARG", strval, 0);
}
else
unbind_variable ("OPTARG");
@ -276,7 +276,7 @@ dogetopts (argc, argv)
strval[0] = (char)sh_optopt;
strval[1] = '\0';
bind_variable ("OPTARG", strval);
bind_variable ("OPTARG", strval, 0);
}
else
{
@ -286,7 +286,7 @@ dogetopts (argc, argv)
return (ret);
}
bind_variable ("OPTARG", sh_optarg);
bind_variable ("OPTARG", sh_optarg, 0);
strval[0] = (char) ret;
strval[1] = '\0';

View file

@ -125,7 +125,7 @@ hash_builtin (list)
if (list == 0 && expunge_hash_table == 0)
{
if (print_hashed_commands (list_portably) == 0)
printf (_("%s: hash table empty\n"), this_command_name);
fprintf (stderr, _("%s: hash table empty\n"), this_command_name);
return (EXECUTION_SUCCESS);
}
@ -165,10 +165,13 @@ hash_builtin (list)
}
else if (absolute_program (w))
continue;
else if (delete && phash_remove (w))
else if (delete)
{
sh_notfound (w);
opt = EXECUTION_FAILURE;
if (phash_remove (w))
{
sh_notfound (w);
opt = EXECUTION_FAILURE;
}
}
else if (add_hashed_command (w, 0))
opt = EXECUTION_FAILURE;

View file

@ -169,7 +169,7 @@ show_longdoc (i)
}
else
for (j = 0; doc[j]; j++)
printf (" %s\n", _(doc[j]));
printf ("%*s%s\n", BASE_INDENT, " ", _(doc[j]));
}
static void

View file

@ -77,11 +77,13 @@ extern int errno;
#endif
extern int current_command_line_count;
extern int force_append_history; /* shopt -s histappend */
int delete_last_history __P((void));
static char *histtime __P((HIST_ENTRY *, const char *));
static void display_history __P((WORD_LIST *));
static int delete_histent __P((int));
static int delete_last_history __P((void));
static void push_history __P((WORD_LIST *));
static int expand_and_print_history __P((WORD_LIST *));
@ -214,15 +216,19 @@ history_builtin (list)
using_history ();
history_lines_in_file = where_history ();
/* The question is whether we reset history_lines_this_session to 0,
losing any history entries we had before we read the new entries
from the history file, or whether we count the new entries we just
read from the file as history lines added during this session.
/* If we're rewriting the history file at shell exit rather than just
appending the lines from this session to it, the question is whether
we reset history_lines_this_session to 0, losing any history entries
we had before we read the new entries from the history file, or
whether we count the new entries we just read from the file as
history lines added during this session.
Right now, we do the latter. This will cause these history entries
to be written to the history file along with any intermediate entries
we add when we do a `history -a', but the alternative is losing
them altogether. */
history_lines_this_session += history_lines_in_file - old_history_lines +
if (force_append_history == 0)
history_lines_this_session += history_lines_in_file - old_history_lines +
history_base - obase;
}
@ -310,7 +316,7 @@ delete_histent (i)
return 1;
}
static int
int
delete_last_history ()
{
register int i;
@ -353,9 +359,11 @@ push_history (list)
If you don't want history -s to remove the compound command from the
history, change #if 0 to #if 1 below. */
#if 0
if (hist_last_line_added && delete_last_history () == 0)
if (hist_last_line_pushed == 0 && hist_last_line_added && delete_last_history () == 0)
#else
if ((hist_last_line_added || (current_command_line_count > 0 && current_command_first_line_saved && command_oriented_history))
if (hist_last_line_pushed == 0 &&
(hist_last_line_added ||
(current_command_line_count > 0 && current_command_first_line_saved && command_oriented_history))
&& delete_last_history () == 0)
#endif
return;
@ -368,6 +376,8 @@ push_history (list)
entry. Without FORCE=1, if current_command_line_count were > 1, the
line would be appended to the entry before the just-deleted entry. */
check_add_history (s, 1); /* obeys HISTCONTROL, HISTIGNORE */
hist_last_line_pushed = 1; /* XXX */
free (s);
}
@ -379,7 +389,7 @@ expand_and_print_history (list)
char *s;
int r, result;
if (hist_last_line_added && delete_last_history () == 0)
if (hist_last_line_pushed == 0 && hist_last_line_added && delete_last_history () == 0)
return EXECUTION_FAILURE;
result = EXECUTION_SUCCESS;
while (list)

View file

@ -1,7 +1,7 @@
This file is jobs.def, from which is created jobs.c.
It implements the builtins "jobs" and "disown" in Bash.
Copyright (C) 1987-2004 Free Software Foundation, Inc.
Copyright (C) 1987-2005 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@ -141,7 +141,7 @@ jobs_builtin (list)
BLOCK_CHILD (set, oset);
job = get_job_spec (list);
if ((job == NO_JOB) || !jobs || !jobs[job])
if ((job == NO_JOB) || jobs == 0 || get_job_by_jid (job) == 0)
{
sh_badjob (list->word->word);
any_failed++;
@ -162,6 +162,7 @@ execute_list_with_replacements (list)
register WORD_LIST *l;
int job, result;
COMMAND *command;
JOB *j;
/* First do the replacement of job specifications with pids. */
for (l = list; l; l = l->next)
@ -171,11 +172,12 @@ execute_list_with_replacements (list)
job = get_job_spec (l);
/* A bad job spec is not really a job spec! Pass it through. */
if (job < 0 || job >= job_slots || !jobs[job])
if (INVALID_JOB (job))
continue;
j = get_job_by_jid (job);
free (l->word->word);
l->word->word = itos (jobs[job]->pgrp);
l->word->word = itos (j->pgrp);
}
}
@ -257,7 +259,7 @@ disown_builtin (list)
? get_job_by_pid ((pid_t) pid_value, 0)
: get_job_spec (list);
if (job == NO_JOB || jobs == 0 || job < 0 || job >= job_slots || jobs[job] == 0)
if (job == NO_JOB || jobs == 0 || INVALID_JOB (job))
{
sh_badjob (list ? list->word->word : "current");
retval = EXECUTION_FAILURE;

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-2004 Free Software Foundation, Inc.
Copyright (C) 1987-2005 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@ -23,8 +23,8 @@ $PRODUCES kill.c
$BUILTIN kill
$FUNCTION kill_builtin
$SHORT_DOC kill [-s sigspec | -n signum | -sigspec] [pid | job]... or kill -l [sigspec]
Send the processes named by PID (or JOB) the signal SIGSPEC. If
$SHORT_DOC kill [-s sigspec | -n signum | -sigspec] pid | jobspec ... or kill -l [sigspec]
Send the processes named by PID (or JOBSPEC) the signal SIGSPEC. If
SIGSPEC is not present, then SIGTERM is assumed. An argument of `-l'
lists the signal names; if arguments follow `-l' they are assumed to
be signal numbers for which names should be listed. Kill is a shell
@ -170,7 +170,7 @@ kill_builtin (list)
{
pid = (pid_t) pid_value;
if ((pid < -1 ? kill_pid (-pid, sig, 1) : kill_pid (pid, sig, 0)) < 0)
if (kill_pid (pid, sig, pid < -1) < 0)
{
if (errno == EINVAL)
sh_invalidsig (sigspec);
@ -192,11 +192,12 @@ kill_builtin (list)
{ /* Must be a job spec. Check it out. */
int job;
sigset_t set, oset;
JOB *j;
BLOCK_CHILD (set, oset);
job = get_job_spec (list);
if (job < 0 || job >= job_slots || !jobs[job])
if (INVALID_JOB (job))
{
if (job != DUP_JOB)
sh_badjob (list->word->word);
@ -204,11 +205,12 @@ kill_builtin (list)
CONTINUE_OR_FAIL;
}
j = get_job_by_jid (job);
/* Job spec used. Kill the process group. If the job was started
without job control, then its pgrp == shell_pgrp, so we have
to be careful. We take the pid of the first job in the pipeline
in that case. */
pid = IS_JOBCONTROL (job) ? jobs[job]->pgrp : jobs[job]->pipe->pid;
pid = IS_JOBCONTROL (job) ? j->pgrp : j->pipe->pid;
UNBLOCK_CHILD (oset);

View file

@ -63,6 +63,8 @@ extern char *strcpy ();
#define BUILTIN_FLAG_SPECIAL 0x01
#define BUILTIN_FLAG_ASSIGNMENT 0x02
#define BASE_INDENT 4
/* If this stream descriptor is non-zero, then write
texinfo documentation to it. */
FILE *documentation_file = (FILE *)NULL;
@ -77,6 +79,10 @@ int inhibit_production = 0;
the builtin name, in `./helpfiles'. */
int separate_helpfiles = 0;
/* Non-zero means to create single C strings for each `longdoc', with
embedded newlines, for ease of translation. */
int single_longdoc_strings = 1;
/* The name of a directory into which the separate external help files will
eventually be installed. */
char *helpfile_directory;
@ -128,7 +134,7 @@ ARRAY *saved_builtins = (ARRAY *)NULL;
char *special_builtins[] =
{
":", ".", "source", "break", "continue", "eval", "exec", "exit",
"export", "readonly", "return", "set", "shift", "trap", "unset",
"export", "readonly", "return", "set", "shift", "times", "trap", "unset",
(char *)NULL
};
@ -225,6 +231,8 @@ main (argc, argv)
separate_helpfiles = 1;
helpfile_directory = argv[arg_index++];
}
else if (strcmp (arg, "-S") == 0)
single_longdoc_strings = 0;
else
{
fprintf (stderr, "%s: Unknown flag %s.\n", argv[0], arg);
@ -373,14 +381,8 @@ array_add (element, array)
array->array = (char **)xrealloc
(array->array, (array->size += array->growth_rate) * array->width);
#if defined (HAVE_BCOPY)
bcopy (&element, (char *) &(array->array[array->sindex]), array->width);
array->sindex++;
bzero ((char *) &(array->array[array->sindex]), array->width);
#else
array->array[array->sindex++] = element;
array->array[array->sindex] = (char *)NULL;
#endif /* !HAVE_BCOPY */
}
/* Free an allocated array and data pointer. */
@ -1058,9 +1060,10 @@ save_builtin (builtin)
}
/* Flags that mean something to write_documentation (). */
#define STRING_ARRAY 1
#define TEXINFO 2
#define PLAINTEXT 4
#define STRING_ARRAY 0x01
#define TEXINFO 0x02
#define PLAINTEXT 0x04
#define HELPFILE 0x08
char *structfile_header[] = {
"/* builtins.c -- the built in shell commands. */",
@ -1271,7 +1274,7 @@ write_longdocs (stream, builtins)
sarray[0] = (char *)xmalloc (l + 1);
sprintf (sarray[0], "%s/%s", helpfile_directory, dname);
sarray[1] = (char *)NULL;
write_documentation (stream, sarray, 0, STRING_ARRAY);
write_documentation (stream, sarray, 0, STRING_ARRAY|HELPFILE);
free (sarray[0]);
}
else
@ -1343,8 +1346,10 @@ write_endifs (stream, defines)
fprintf (stream, " */\n");
}
/* Write DOCUMENTAION to STREAM, perhaps surrounding it with double-quotes
and quoting special characters in the string. */
/* Write DOCUMENTATION to STREAM, perhaps surrounding it with double-quotes
and quoting special characters in the string. Handle special things for
internationalization (gettext) and the single-string vs. multiple-strings
issues. */
void
write_documentation (stream, documentation, indentation, flags)
FILE *stream;
@ -1353,33 +1358,59 @@ write_documentation (stream, documentation, indentation, flags)
{
register int i, j;
register char *line;
int string_array, texinfo;
int string_array, texinfo, base_indent, last_cpp, filename_p;
if (!stream)
return;
string_array = flags & STRING_ARRAY;
if (string_array)
fprintf (stream, " {\n#if defined (HELP_BUILTIN)\n");
filename_p = flags & HELPFILE;
for (i = 0, texinfo = (flags & TEXINFO); line = documentation[i]; i++)
if (string_array)
{
/* Allow #ifdef's to be written out verbatim. */
fprintf (stream, " {\n#if defined (HELP_BUILTIN)\n"); /* } */
if (single_longdoc_strings)
{
if (filename_p == 0)
fprintf (stream, "N_(\" "); /* the empty string translates specially. */
else
fprintf (stream, "\"");
}
}
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++)
{
/* Allow #ifdef's to be written out verbatim, but don't put them into
separate help files. */
if (*line == '#')
{
if (string_array)
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)
fprintf (stream, " N_(\"");
if (string_array && single_longdoc_strings == 0)
{
if (filename_p == 0)
fprintf (stream, " N_(\" "); /* the empty string translates specially. */
else
fprintf (stream, " \"");
}
if (indentation)
for (j = 0; j < indentation; j++)
fprintf (stream, " ");
/* Don't indent the first line, because of how the help builtin works. */
if (i == 0)
indentation += base_indent;
if (string_array)
{
for (j = 0; line[j]; j++)
@ -1397,7 +1428,16 @@ write_documentation (stream, documentation, indentation, flags)
}
/* closing right paren for gettext */
fprintf (stream, "\"),\n");
if (single_longdoc_strings == 0)
{
if (filename_p == 0)
fprintf (stream, "\"),\n");
else
fprintf (stream, "\",\n");
}
else if (documentation[i+1])
/* don't add extra newline after last line */
fprintf (stream, "\\n\\\n");
}
else if (texinfo)
{
@ -1421,6 +1461,15 @@ write_documentation (stream, documentation, indentation, flags)
fprintf (stream, "%s\n", line);
}
/* closing right paren for gettext */
if (string_array && single_longdoc_strings)
{
if (filename_p == 0)
fprintf (stream, "\"),\n");
else
fprintf (stream, "\",\n");
}
if (string_array)
fprintf (stream, "#endif /* HELP_BUILTIN */\n (char *)NULL\n};\n");
}

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-2003 Free Software Foundation, Inc.
Copyright (C) 1997-2005 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@ -23,7 +23,7 @@ $PRODUCES printf.c
$BUILTIN printf
$FUNCTION printf_builtin
$SHORT_DOC printf format [arguments]
$SHORT_DOC printf [-v var] format [arguments]
printf formats and prints ARGUMENTS under control of the FORMAT. FORMAT
is a character string which contains three types of objects: plain
characters, which are simply copied to standard output, character escape
@ -32,6 +32,8 @@ format specifications, each of which causes printing of the next successive
argument. In addition to the standard printf(1) formats, %b means to
expand backslash escape sequences in the corresponding argument, and %q
means to quote the argument in a way that can be reused as shell input.
If the -v option is supplied, the output is placed into the value of the
shell variable VAR rather than being sent to the standard output.
$END
#include <config.h>
@ -74,28 +76,61 @@ $END
extern int errno;
#endif
#define PC(c) \
do { \
char b[2]; \
tw++; \
b[0] = c; b[1] = '\0'; \
if (vflag) \
vbadd (b, 1); \
else \
putchar (c); \
} while (0)
#define PF(f, func) \
do { \
char *b = 0; \
int nw; \
if (have_fieldwidth && have_precision) \
tw += printf(f, fieldwidth, precision, func); \
nw = asprintf(&b, f, fieldwidth, precision, func); \
else if (have_fieldwidth) \
tw += printf(f, fieldwidth, func); \
nw = asprintf(&b, f, fieldwidth, func); \
else if (have_precision) \
tw += printf(f, precision, func); \
nw = asprintf(&b, f, precision, func); \
else \
tw += printf(f, func); \
nw = asprintf(&b, f, func); \
tw += nw; \
if (b) \
{ \
if (vflag) \
(void)vbadd (b, nw); \
else \
(void)fputs (b, stdout); \
free (b); \
} \
} while (0)
/* We free the buffer used by mklong() if it's `too big'. */
#define PRETURN(value) \
do \
{ \
if (vflag) \
{ \
bind_variable (vname, vbuf, 0); \
stupidly_hack_special_variables (vname); \
} \
if (conv_bufsize > 4096 ) \
{ \
free(conv_buf); \
free (conv_buf); \
conv_bufsize = 0; \
conv_buf = 0; \
} \
if (vbsize > 4096) \
{ \
free (vbuf); \
vbsize = 0; \
vbuf = 0; \
} \
fflush (stdout); \
return (value); \
} \
@ -105,9 +140,10 @@ extern int errno;
#define LENMODS "hjlLtz"
static void printf_erange __P((char *));
static void printstr __P((char *, char *, int, int, int));
static int printstr __P((char *, char *, int, int, int));
static int tescape __P((char *, char *, int *));
static char *bexpand __P((char *, int, int *, int *));
static char *vbadd __P((char *, int));
static char *mklong __P((char *, char *, size_t));
static int getchr __P((void));
static char *getstr __P((void));
@ -132,6 +168,14 @@ static WORD_LIST *garglist;
static int retval;
static int conversion_error;
/* printf -v var support */
static int vflag = 0;
static char *vbuf, *vname;
static size_t vbsize;
static int vblen;
static intmax_t tw;
static char *conv_buf;
static size_t conv_bufsize;
@ -141,14 +185,35 @@ printf_builtin (list)
{
int ch, fieldwidth, precision;
int have_fieldwidth, have_precision;
intmax_t tw;
char convch, thisch, nextch, *format, *modstart, *fmt, *start;
conversion_error = 0;
retval = EXECUTION_SUCCESS;
if (no_options (list))
return (EX_USAGE);
vflag = 0;
reset_internal_getopt ();
while ((ch = internal_getopt (list, "v:")) != -1)
{
switch (ch)
{
case 'v':
if (legal_identifier (vname = list_optarg))
{
vflag = 1;
vblen = 0;
}
else
{
sh_invalidid (vname);
return (EX_USAGE);
}
break;
default:
builtin_usage ();
return (EX_USAGE);
}
}
list = loptend; /* skip over possible `--' */
if (list == 0)
@ -161,6 +226,7 @@ printf_builtin (list)
return (EXECUTION_SUCCESS);
format = list->word->word;
tw = 0;
garglist = list->next;
@ -189,14 +255,14 @@ printf_builtin (list)
/* A NULL third argument to tescape means to bypass the
special processing for arguments to %b. */
fmt += tescape (fmt, &nextch, (int *)NULL);
putchar (nextch);
PC (nextch);
fmt--; /* for loop will increment it for us again */
continue;
}
if (*fmt != '%')
{
putchar (*fmt);
PC (*fmt);
continue;
}
@ -205,7 +271,7 @@ printf_builtin (list)
if (*fmt == '%') /* %% prints a % */
{
putchar ('%');
PC ('%');
continue;
}
@ -235,8 +301,20 @@ printf_builtin (list)
precision = getint ();
}
else
while (DIGIT (*fmt))
fmt++;
{
/* Negative precisions are allowed but treated as if the
precision were missing; I would like to allow a leading
`+' in the precision number as an extension, but lots
of asprintf/fprintf implementations get this wrong. */
#if 0
if (*fmt == '-' || *fmt == '+')
#else
if (*fmt == '-')
#endif
fmt++;
while (DIGIT (*fmt))
fmt++;
}
}
/* skip possible format modifiers */
@ -297,21 +375,27 @@ printf_builtin (list)
case 'b': /* expand escapes in argument */
{
char *p, *xp;
int rlen;
int rlen, r;
p = getstr ();
ch = rlen = 0;
ch = rlen = r = 0;
xp = bexpand (p, strlen (p), &ch, &rlen);
if (xp)
{
/* Have to use printstr because of possible NUL bytes
in XP -- printf does not handle that well. */
printstr (start, xp, rlen, fieldwidth, precision);
r = printstr (start, xp, rlen, fieldwidth, precision);
if (r < 0)
{
sh_wrerror ();
clearerr (stdout);
retval = EXECUTION_FAILURE;
}
free (xp);
}
if (ch)
if (ch || r < 0)
PRETURN (retval);
break;
}
@ -319,7 +403,9 @@ printf_builtin (list)
case 'q': /* print with shell quoting */
{
char *p, *xp;
int r;
r = 0;
p = getstr ();
if (ansic_shouldquote (p))
xp = ansic_quote (p, 0, (int *)0);
@ -328,9 +414,17 @@ printf_builtin (list)
if (xp)
{
/* Use printstr to get fieldwidth and precision right. */
printstr (start, xp, strlen (xp), fieldwidth, precision);
r = printstr (start, xp, strlen (xp), fieldwidth, precision);
if (r < 0)
{
sh_wrerror ();
clearerr (stdout);
}
free (xp);
}
if (r < 0)
PRETURN (EXECUTION_FAILURE);
break;
}
@ -412,6 +506,13 @@ printf_builtin (list)
modstart[0] = thisch;
modstart[1] = nextch;
}
if (ferror (stdout))
{
sh_wrerror ();
clearerr (stdout);
PRETURN (EXECUTION_FAILURE);
}
}
while (garglist && garglist != list->next);
@ -429,7 +530,7 @@ printf_erange (s)
}
/* We duplicate a lot of what printf(3) does here. */
static void
static int
printstr (fmt, string, len, fieldwidth, precision)
char *fmt; /* format */
char *string; /* expanded string argument */
@ -443,7 +544,11 @@ printstr (fmt, string, len, fieldwidth, precision)
int padlen, nc, ljust, i;
int fw, pr; /* fieldwidth and precision */
#if 0
if (string == 0 || *string == '\0')
#else
if (string == 0 || len == 0)
#endif
return;
#if 0
@ -518,15 +623,17 @@ printstr (fmt, string, len, fieldwidth, precision)
/* leading pad characters */
for (; padlen > 0; padlen--)
putchar (' ');
PC (' ');
/* output NC characters from STRING */
for (i = 0; i < nc; i++)
putchar (string[i]);
PC (string[i]);
/* output any necessary trailing padding */
for (; padlen < 0; padlen++)
putchar (' ');
PC (' ');
return (ferror (stdout) ? -1 : 0);
}
/* Convert STRING by expanding the escape sequences specified by the
@ -644,7 +751,11 @@ 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)
#endif
{
if (sawc)
*sawc = 0;
@ -680,6 +791,37 @@ bexpand (string, len, sawc, lenp)
return ret;
}
static char *
vbadd (buf, blen)
char *buf;
int blen;
{
size_t nlen;
nlen = vblen + blen + 1;
if (nlen >= vbsize)
{
vbsize = ((nlen + 63) >> 6) << 6;
vbuf = (char *)xrealloc (vbuf, vbsize);
}
if (blen == 1)
vbuf[vblen++] = buf[0];
else
{
FASTCOPY (buf, vbuf + vblen, blen);
vblen += blen;
}
vbuf[vblen] = '\0';
#ifdef DEBUG
if (strlen (vbuf) != vblen)
internal_error ("printf:vbadd: vblen (%d) != strlen (vbuf) (%d)", vblen, strlen (vbuf));
#endif
return vbuf;
}
static char *
mklong (str, modifiers, mlen)
char *str;

View file

@ -40,7 +40,10 @@
#include "../command.h"
#include "../general.h"
#include "../sig.h"
#ifndef errno
extern int errno;
#endif
int nw;

View file

@ -1,7 +1,7 @@
This file is pushd.def, from which is created pushd.c. It implements the
builtins "pushd", "popd", and "dirs" in Bash.
Copyright (C) 1987-2003 Free Software Foundation, Inc.
Copyright (C) 1987-2004 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@ -151,13 +151,20 @@ int
pushd_builtin (list)
WORD_LIST *list;
{
WORD_LIST *orig_list;
char *temp, *current_directory, *top;
int j, flags;
int j, flags, skipopt;
intmax_t num;
char direction;
orig_list = list;
if (list && list->word && ISOPTION (list->word->word, '-'))
list = list->next;
{
list = list->next;
skipopt = 1;
}
else
skipopt = 0;
/* If there is no argument list then switch current and
top of list. */
@ -181,7 +188,7 @@ pushd_builtin (list)
return j;
}
for (flags = 0; list; list = list->next)
for (flags = 0; skipopt == 0 && list; list = list->next)
{
if (ISOPTION (list->word->word, 'n'))
{
@ -265,7 +272,7 @@ pushd_builtin (list)
if (current_directory == 0)
return (EXECUTION_FAILURE);
j = ((flags & NOCD) == 0) ? cd_builtin (list) : EXECUTION_SUCCESS;
j = ((flags & NOCD) == 0) ? cd_builtin (skipopt ? orig_list : list) : EXECUTION_SUCCESS;
if (j == EXECUTION_SUCCESS)
{
add_dirstack_element ((flags & NOCD) ? savestring (list->word->word) : current_directory);
@ -499,9 +506,11 @@ cd_to_string (name)
char *name;
{
WORD_LIST *tlist;
WORD_LIST *dir;
int result;
tlist = make_word_list (make_word (name), NULL);
dir = make_word_list (make_word (name), NULL);
tlist = make_word_list (make_word ("--"), dir);
result = cd_builtin (tlist);
dispose_words (tlist);
return (result);
@ -648,11 +657,11 @@ get_directory_stack ()
}
#ifdef LOADABLE_BUILTIN
static char *dirs_doc[] = {
static char * const dirs_doc[] = {
N_("Display the list of currently remembered directories. Directories"),
N_("find their way onto the list with the `pushd' command; you can get"),
N_("back up through the list with the `popd' command."),
N_(""),
N_(" "),
N_("The -l flag specifies that `dirs' should not print shorthand versions"),
N_("of directories which are relative to your home directory. This means"),
N_("that `~/bin' might be displayed as `/homes/bfox/bin'. The -v flag"),
@ -660,54 +669,54 @@ static char *dirs_doc[] = {
N_("prepending the directory name with its position in the stack. The -p"),
N_("flag does the same thing, but the stack position is not prepended."),
N_("The -c flag clears the directory stack by deleting all of the elements."),
N_(""),
N_(" "),
N_("+N displays the Nth entry counting from the left of the list shown by"),
N_(" dirs when invoked without options, starting with zero."),
N_(""),
N_(" "),
N_("-N displays the Nth entry counting from the right of the list shown by"),
N_(" dirs when invoked without options, starting with zero."),
(char *)NULL
};
static char *pushd_doc[] = {
static char * const pushd_doc[] = {
N_("Adds a directory to the top of the directory stack, or rotates"),
N_("the stack, making the new top of the stack the current working"),
N_("directory. With no arguments, exchanges the top two directories."),
N_(""),
N_(" "),
N_("+N Rotates the stack so that the Nth directory (counting"),
N_(" from the left of the list shown by `dirs', starting with"),
N_(" zero) is at the top."),
N_(""),
N_(" "),
N_("-N Rotates the stack so that the Nth directory (counting"),
N_(" from the right of the list shown by `dirs', starting with"),
N_(" zero) is at the top."),
N_(""),
N_(" "),
N_("-n suppress the normal change of directory when adding directories"),
N_(" to the stack, so only the stack is manipulated."),
N_(""),
N_(" "),
N_("dir adds DIR to the directory stack at the top, making it the"),
N_(" new current working directory."),
N_(""),
N_(" "),
N_("You can see the directory stack with the `dirs' command."),
(char *)NULL
};
static char *popd_doc[] = {
static char * const popd_doc[] = {
N_("Removes entries from the directory stack. With no arguments,"),
N_("removes the top directory from the stack, and cd's to the new"),
N_("top directory."),
N_(""),
N_(" "),
N_("+N removes the Nth entry counting from the left of the list"),
N_(" shown by `dirs', starting with zero. For example: `popd +0'"),
N_(" removes the first directory, `popd +1' the second."),
N_(""),
N_(" "),
N_("-N removes the Nth entry counting from the right of the list"),
N_(" shown by `dirs', starting with zero. For example: `popd -0'"),
N_(" removes the last directory, `popd -1' the next to last."),
N_(""),
N_(" "),
N_("-n suppress the normal change of directory when removing directories"),
N_(" from the stack, so only the stack is manipulated."),
N_(""),
N_(" "),
N_("You can see the directory stack with the `dirs' command."),
(char *)NULL
};

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-2004 Free Software Foundation, Inc.
Copyright (C) 1987-2005 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@ -79,6 +79,10 @@ $END
#include <readline/readline.h>
#endif
#if defined (BUFFERED_INPUT)
# include "input.h"
#endif
#if !defined(errno)
extern int errno;
#endif
@ -124,7 +128,7 @@ read_builtin (list)
WORD_LIST *list;
{
register char *varname;
int size, i, pass_next, saw_escape, eof, opt, retval, code;
int size, i, nr, pass_next, saw_escape, eof, opt, retval, code;
int input_is_tty, input_is_pipe, unbuffered_read;
int raw, edit, nchars, silent, have_timeout, fd;
unsigned int tmout;
@ -173,7 +177,7 @@ read_builtin (list)
#endif
tmout = 0; /* no timeout */
nchars = input_is_tty = input_is_pipe = unbuffered_read = have_timeout = 0;
nr = nchars = input_is_tty = input_is_pipe = unbuffered_read = have_timeout = 0;
delim = '\n'; /* read until newline */
reset_internal_getopt ();
@ -273,10 +277,15 @@ read_builtin (list)
begin_unwind_frame ("read_builtin");
#if defined (BUFFERED_INPUT)
if (interactive == 0 && default_buffered_input >= 0 && fd_is_bash_input (fd))
sync_buffered_stream (default_buffered_input);
#endif
input_is_tty = isatty (fd);
if (input_is_tty == 0)
#ifndef __CYGWIN__
input_is_pipe = (lseek (0, 0L, SEEK_CUR) < 0) && (errno == ESPIPE);
input_is_pipe = (lseek (fd, 0L, SEEK_CUR) < 0) && (errno == ESPIPE);
#else
input_is_pipe = 1;
#endif
@ -425,11 +434,11 @@ read_builtin (list)
newline pair still disappears from the input. */
if (pass_next)
{
pass_next = 0;
if (c == '\n')
i--; /* back up over the CTLESC */
else
input_string[i++] = c;
pass_next = 0;
goto add_char;
continue;
}
@ -450,9 +459,11 @@ read_builtin (list)
input_string[i++] = CTLESC;
}
add_char:
input_string[i++] = c;
nr++;
if (nchars > 0 && i >= nchars)
if (nchars > 0 && nr >= nchars)
break;
}
input_string[i] = '\0';
@ -515,7 +526,7 @@ read_builtin (list)
if (alist)
{
word_list_remove_quoted_nulls (alist);
assign_array_var_from_word_list (var, alist);
assign_array_var_from_word_list (var, alist, 0);
dispose_words (alist);
}
xfree (input_string);
@ -544,11 +555,11 @@ read_builtin (list)
if (saw_escape)
{
t = dequote_string (input_string);
var = bind_variable ("REPLY", t);
var = bind_variable ("REPLY", t, 0);
free (t);
}
else
var = bind_variable ("REPLY", input_string);
var = bind_variable ("REPLY", input_string, 0);
VUNSETATTR (var, att_invisible);
free (input_string);
@ -627,10 +638,24 @@ read_builtin (list)
return (EXECUTION_FAILURE);
}
#if 0
/* This has to be done this way rather than using string_list
and list_string because Posix.2 says that the last variable gets the
remaining words and their intervening separators. */
input_string = strip_trailing_ifs_whitespace (input_string, ifs_chars, saw_escape);
#else
/* Check whether or not the number of fields is exactly the same as the
number of variables. */
if (*input_string)
{
t1 = input_string;
t = get_word_from_string (&input_string, ifs_chars, &e);
if (*input_string == 0)
input_string = t;
else
input_string = strip_trailing_ifs_whitespace (t1, ifs_chars, saw_escape);
}
#endif
if (saw_escape)
{
@ -654,11 +679,11 @@ bind_read_variable (name, value)
{
#if defined (ARRAY_VARS)
if (valid_array_reference (name) == 0)
return (bind_variable (name, value));
return (bind_variable (name, value, 0));
else
return (assign_array_element (name, value));
return (assign_array_element (name, value, 0));
#else /* !ARRAY_VARS */
return bind_variable (name, value);
return bind_variable (name, value, 0);
#endif /* !ARRAY_VARS */
}
@ -672,7 +697,7 @@ edit_line (p)
char *ret;
int len;
if (!bash_readline_initialized)
if (bash_readline_initialized == 0)
initialize_readline ();
old_attempted_completion_function = rl_attempted_completion_function;
rl_attempted_completion_function = (rl_completion_func_t *)NULL;

View file

@ -2,7 +2,7 @@ This file is reserved.def, in which the shell reserved words are defined.
It has no direct C file production, but defines builtins for the Bash
builtin help command.
Copyright (C) 1987-2002 Free Software Foundation, Inc.
Copyright (C) 1987-2005 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@ -73,12 +73,13 @@ $END
$BUILTIN if
$SHORT_DOC if COMMANDS; then COMMANDS; [ elif COMMANDS; then COMMANDS; ]... [ else COMMANDS; ] fi
The if COMMANDS are executed. If the exit status is zero, then the then
COMMANDS are executed. Otherwise, each of the elif COMMANDS are executed
in turn, and if the exit status is zero, the corresponding then COMMANDS
are executed and the if command completes. Otherwise, the else COMMANDS
are executed, if present. The exit status is the exit status of the last
command executed, or zero if no condition tested true.
The `if COMMANDS' list is executed. If its exit status is zero, then the
`then COMMANDS' list is executed. Otherwise, each `elif COMMANDS' list is
executed in turn, and if its exit status is zero, the corresponding
`then COMMANDS' list is executed and the if command completes. Otherwise,
the `else COMMANDS' list is executed, if present. The exit status of the
entire construct is the exit status of the last command executed, or zero
if no condition tested true.
$END
$BUILTIN while
@ -109,11 +110,12 @@ $END
$BUILTIN %
$DOCNAME fg_percent
$SHORT_DOC %[DIGITS | WORD] [&]
This is similar to the `fg' command. Resume a stopped or background
job. If you specifiy DIGITS, then that job is used. If you specify
WORD, then the job whose name begins with WORD is used. Following the
job specification with a `&' places the job in the background.
$SHORT_DOC JOB_SPEC [&]
Equivalent to the JOB_SPEC argument to the `fg' command. Resume a
stopped or background job. JOB_SPEC can specify either a job name
or a job number. Following JOB_SPEC with a `&' places the job in
the background, as if the job specification had been supplied as an
argument to `bg'.
$END
$BUILTIN (( ... ))
@ -145,9 +147,8 @@ $BUILTIN variables
$DOCNAME variable_help
$SHORT_DOC variables - Some variable names and meanings
BASH_VERSION Version information for this Bash.
CDPATH A colon separated list of directories to search
when the argument to `cd' is not found in the current
directory.
CDPATH A colon-separated list of directories to search
for directries given as arguments to `cd'.
GLOBIGNORE A colon-separated list of patterns describing filenames to
be ignored by pathname expansion.
#if defined (HISTORY)

View file

@ -1,7 +1,7 @@
This file is set.def, from which is created set.c.
It implements the "set" and "unset" builtins in Bash.
Copyright (C) 1987-2002 Free Software Foundation, Inc.
Copyright (C) 1987-2004 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@ -128,11 +128,13 @@ $SHORT_DOC set [--abefhkmnptuvxBCHP] [-o option] [arg ...]
-E If set, the ERR trap is inherited by shell functions.
#if defined (BANG_HISTORY)
-H Enable ! style history substitution. This flag is on
by default.
by default when the shell is interactive.
#endif /* BANG_HISTORY */
-P If set, do not follow symbolic links when executing commands
such as cd which change the current directory.
-T If set, the DEBUG trap is inherited by shell functions.
- Assign any remaining arguments to the positional parameters.
The -x and -v options are turned off.
Using + rather than - causes these flags to be turned off. The
flags can also be used upon invocation of the shell. The current
@ -311,7 +313,7 @@ set_ignoreeof (on_or_off, option_name)
ignoreeof = on_or_off == FLAG_ON;
unbind_variable ("ignoreeof");
if (ignoreeof)
bind_variable ("IGNOREEOF", "10");
bind_variable ("IGNOREEOF", "10", 0);
else
unbind_variable ("IGNOREEOF");
sv_ignoreeof ("IGNOREEOF");
@ -327,7 +329,7 @@ set_posix_mode (on_or_off, option_name)
if (posixly_correct == 0)
unbind_variable ("POSIXLY_CORRECT");
else
bind_variable ("POSIXLY_CORRECT", "y");
bind_variable ("POSIXLY_CORRECT", "y", 0);
sv_strict_posix ("POSIXLY_CORRECT");
return (0);
}
@ -503,7 +505,7 @@ set_shellopts ()
else
exported = 0;
v = bind_variable ("SHELLOPTS", value);
v = bind_variable ("SHELLOPTS", value, 0);
/* Turn the read-only attribute back on, and turn off the export attribute
if it was set implicitly by mark_modified_vars and SHELLOPTS was not

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-2003 Free Software Foundation, Inc.
Copyright (C) 1987-2004 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@ -111,6 +111,7 @@ set_or_show_attributes (list, attribute, nodefs)
{
register SHELL_VAR *var;
int assign, undo, functions_only, arrays_only, any_failed, assign_error, opt;
int aflags;
char *name;
#if defined (ARRAY_VARS)
WORD_LIST *nlist, *tlist;
@ -175,8 +176,16 @@ set_or_show_attributes (list, attribute, nodefs)
/* xxx [-np] name[=value] */
assign = assignment (name, 0);
aflags = 0;
if (assign)
name[assign] = '\0';
{
name[assign] = '\0';
if (name[assign - 1] == '+')
{
aflags |= ASS_APPEND;
name[assign - 1] = '\0';
}
}
if (legal_identifier (name) == 0)
{
@ -192,6 +201,8 @@ set_or_show_attributes (list, attribute, nodefs)
if (assign) /* xxx [-np] name=value */
{
name[assign] = '=';
if (aflags & ASS_APPEND)
name[assign - 1] = '+';
#if defined (ARRAY_VARS)
/* Let's try something here. Turn readonly -a xxx=yyy into
declare -ra xxx=yyy and see what that gets us. */
@ -217,6 +228,8 @@ set_or_show_attributes (list, attribute, nodefs)
if (do_assignment_no_expand (name) == 0)
assign_error++;
name[assign] = '\0';
if (aflags & ASS_APPEND)
name[assign - 1] = '\0';
}
set_var_attribute (name, attribute, undo);
@ -396,13 +409,15 @@ set_var_attribute (name, attribute, undo)
{
tvalue = var_isset (tv) ? savestring (value_cell (tv)) : savestring ("");
var = bind_variable (tv->name, tvalue);
var = bind_variable (tv->name, tvalue, 0);
var->attributes |= tv->attributes & ~att_tempvar;
VSETATTR (tv, att_propagate);
if (var->context != 0)
VSETATTR (var, att_propagate);
SETVARATTR (tv, attribute, undo); /* XXX */
stupidly_hack_special_variables (tv->name);
free (tvalue);
}
else
@ -410,7 +425,7 @@ set_var_attribute (name, attribute, undo)
var = find_variable_internal (name, 0);
if (var == 0)
{
var = bind_variable (name, (char *)NULL);
var = bind_variable (name, (char *)NULL, 0);
VSETATTR (var, att_invisible);
}
else if (var->context != 0)

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-2003 Free Software Foundation, Inc.
Copyright (C) 1994-2005 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@ -64,7 +64,7 @@ extern int check_hashed_filenames, promptvars;
extern int cdspelling, expand_aliases;
extern int extended_quote;
extern int check_window_size;
extern int glob_ignore_case;
extern int glob_ignore_case, match_ignore_case;
extern int hup_on_exit;
extern int xpg_echo;
extern int gnu_error_format;
@ -134,13 +134,13 @@ static struct {
{ "failglob", &fail_glob_expansion, (shopt_set_func_t *)NULL },
#if defined (READLINE)
{ "force_fignore", &force_fignore, (shopt_set_func_t *)NULL },
{ "gnu_errfmt", &gnu_error_format, (shopt_set_func_t *)NULL },
{ "histreedit", &history_reediting, (shopt_set_func_t *)NULL },
#endif
{ "gnu_errfmt", &gnu_error_format, (shopt_set_func_t *)NULL },
#if defined (HISTORY)
{ "histappend", &force_append_history, (shopt_set_func_t *)NULL },
#endif
#if defined (READLINE)
{ "histreedit", &history_reediting, (shopt_set_func_t *)NULL },
{ "histverify", &hist_verify, (shopt_set_func_t *)NULL },
{ "hostcomplete", &perform_hostname_completion, enable_hostname_completion },
#endif
@ -155,6 +155,7 @@ static struct {
{ "no_empty_cmd_completion", &no_empty_command_completion, (shopt_set_func_t *)NULL },
#endif
{ "nocaseglob", &glob_ignore_case, (shopt_set_func_t *)NULL },
{ "nocasematch", &match_ignore_case, (shopt_set_func_t *)NULL },
{ "nullglob", &allow_null_glob_expansion, (shopt_set_func_t *)NULL },
#if defined (PROGRAMMABLE_COMPLETION)
{ "progcomp", &prog_completion_enabled, (shopt_set_func_t *)NULL },

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-2004 Free Software Foundation, Inc.
Copyright (C) 1987-2005 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@ -214,7 +214,6 @@ showtrap (i)
char *t, *p, *sn;
p = trap_list[i];
if (p == (char *)DEFAULT_SIG)
return;

View file

@ -74,7 +74,7 @@ $END
extern int find_reserved_word __P((char *));
extern char *this_command_name;
extern int expand_aliases;
extern int expand_aliases, posixly_correct;
/* For each word in LIST, find out what the shell is going to do with
it as a simple command. i.e., which file would this shell use to
@ -201,6 +201,7 @@ type_builtin (list)
* CDESC_PATH_ONLY print the path for type -p
* CDESC_FORCE_PATH force a path search for type -P
* CDESC_NOFUNCS skip function lookup for type -f
* CDESC_ABSPATH convert to absolute path, no ./ prefix
*
* CDESC_ALL says whether or not to look for all occurrences of COMMAND, or
* return after finding it once.
@ -359,8 +360,9 @@ describe_command (command, dflags)
/* If we found the command as itself by looking through $PATH, it
probably doesn't exist. Check whether or not the command is an
executable file. If it's not, don't report a match. */
if (STREQ (full_path, command))
executable file. If it's not, don't report a match. This is
the default posix mode behavior */
if (STREQ (full_path, command) || posixly_correct)
{
f = file_status (full_path);
if ((f & FS_EXECABLE) == 0)
@ -370,9 +372,17 @@ describe_command (command, dflags)
if (all == 0)
break;
}
else if (ABSPATH (full_path))
; /* placeholder; don't need to do anything yet */
else if (dflags & (CDESC_REUSABLE|CDESC_PATH_ONLY|CDESC_SHORTDESC))
full_path = sh_makepath ((char *)NULL, full_path, MP_DOCWD);
{
f = MP_DOCWD | ((dflags & CDESC_ABSPATH) ? MP_RMDOT : 0);
full_path = sh_makepath ((char *)NULL, full_path, f);
}
}
/* If we require a full path and don't have one, make one */
else if ((dflags & CDESC_ABSPATH) && ABSPATH (full_path) == 0)
full_path = sh_makepath ((char *)NULL, full_path, MP_DOCWD|MP_RMDOT);
found_file++;
found = 1;

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-2003 Free Software Foundation, Inc.
Copyright (C) 1987-2005 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@ -24,7 +24,7 @@ $PRODUCES ulimit.c
$BUILTIN ulimit
$FUNCTION ulimit_builtin
$DEPENDS_ON !_MINIX
$SHORT_DOC ulimit [-SHacdflmnpstuv] [limit]
$SHORT_DOC ulimit [-SHacdfilmnpqstuvx] [limit]
Ulimit provides control over the resources available to processes
started by the shell, on systems that allow such control. If an
option is given, it is interpreted as follows:
@ -35,14 +35,17 @@ option is given, it is interpreted as follows:
-c the maximum size of core files created
-d the maximum size of a process's data segment
-f the maximum size of files created by the shell
-i the maximum number of pending signals
-l the maximum size a process may lock into memory
-m the maximum resident set size
-n the maximum number of open file descriptors
-p the pipe buffer size
-q the maximum number of bytes in POSIX message queues
-s the maximum stack size
-t the maximum amount of cpu time in seconds
-u the maximum number of user processes
-v the size of virtual memory
-v the size of virtual memory
-x the maximum number of file locks
If LIMIT is given, it is the new value of the specified resource;
the special LIMIT values `soft', `hard', and `unlimited' stand for
@ -200,6 +203,9 @@ static RESOURCE_LIMITS limits[] = {
{ 'd', RLIMIT_DATA, 1024, "data seg size", "kbytes" },
#endif
{ 'f', RLIMIT_FILESIZE, 1024, "file size", "blocks" },
#ifdef RLIMIT_SIGPENDING
{ 'i', RLIMIT_SIGPENDING, 1, "pending signals", (char *)NULL },
#endif
#ifdef RLIMIT_MEMLOCK
{ 'l', RLIMIT_MEMLOCK, 1024, "max locked memory", "kbytes" },
#endif
@ -208,6 +214,9 @@ static RESOURCE_LIMITS limits[] = {
#endif /* RLIMIT_RSS */
{ 'n', RLIMIT_OPENFILES, 1, "open files", (char *)NULL},
{ 'p', RLIMIT_PIPESIZE, 512, "pipe size", "512 bytes" },
#ifdef RLIMIT_MSGQUEUE
{ 'q', RLIMIT_MSGQUEUE, 1, "POSIX message queues", "bytes" },
#endif
#ifdef RLIMIT_STACK
{ 's', RLIMIT_STACK, 1024, "stack size", "kbytes" },
#endif
@ -220,6 +229,9 @@ static RESOURCE_LIMITS limits[] = {
#endif
#ifdef RLIMIT_SWAP
{ 'w', RLIMIT_SWAP, 1024, "swap size", "kbytes" },
#endif
#ifdef RLIMIT_LOCKS
{ 'x', RLIMIT_LOCKS, 1, "file locks", (char *)NULL },
#endif
{ -1, -1, -1, (char *)NULL, (char *)NULL }
};
@ -605,14 +617,19 @@ pipesize (valuep)
*valuep = (RLIMTYPE) PIPE_BUF;
return 0;
#else
# if defined (PIPESIZE)
# if defined (_POSIX_PIPE_BUF)
*valuep = (RLIMTYPE) _POSIX_PIPE_BUF;
return 0;
# else
# if defined (PIPESIZE)
/* This is defined by running a program from the Makefile. */
*valuep = (RLIMTYPE) PIPESIZE;
return 0;
# else
# else
errno = EINVAL;
return -1;
# endif /* PIPESIZE */
# endif /* PIPESIZE */
# endif /* _POSIX_PIPE_BUF */
#endif /* PIPE_BUF */
}
@ -647,11 +664,11 @@ print_all_limits (mode)
for (i = 0; limits[i].option > 0; i++)
{
if (get_limit (i, &softlim, &hardlim) < 0)
if (get_limit (i, &softlim, &hardlim) == 0)
printone (i, (mode & LIMIT_SOFT) ? softlim : hardlim, 1);
else if (errno != EINVAL)
builtin_error ("%s: cannot get limit: %s", limits[i].description,
strerror (errno));
else
printone (i, (mode & LIMIT_SOFT) ? softlim : hardlim, 1);
}
}
@ -670,7 +687,7 @@ printone (limind, curlim, pdesc)
else
sprintf (unitstr, "(-%c) ", limits[limind].option);
printf ("%-18s %16s", limits[limind].description, unitstr);
printf ("%-20s %16s", limits[limind].description, unitstr);
}
if (curlim == RLIM_INFINITY)
puts ("unlimited");

View file

@ -1,7 +1,7 @@
This file is wait.def, from which is created wait.c.
It implements the builtin "wait" in Bash.
Copyright (C) 1987-2004 Free Software Foundation, Inc.
Copyright (C) 1987-2005 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@ -150,7 +150,7 @@ wait_builtin (list)
BLOCK_CHILD (set, oset);
job = get_job_spec (list);
if (job < 0 || job >= job_slots || !jobs[job])
if (INVALID_JOB (job))
{
if (job != DUP_JOB)
sh_badjob (list->word->word);

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 Free Software Foundation, Inc.
/* Copyright (C) 1993-2005 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@ -67,17 +67,26 @@ enum command_type { cm_for, cm_case, cm_while, cm_if, cm_simple, cm_select,
cm_arith, cm_cond, cm_arith_for, cm_subshell };
/* Possible values for the `flags' field of a WORD_DESC. */
#define W_HASDOLLAR 0x0001 /* Dollar sign present. */
#define W_QUOTED 0x0002 /* Some form of quote character is present. */
#define W_ASSIGNMENT 0x0004 /* This word is a variable assignment. */
#define W_GLOBEXP 0x0008 /* This word is the result of a glob expansion. */
#define W_NOSPLIT 0x0010 /* Do not perform word splitting on this word. */
#define W_NOGLOB 0x0020 /* Do not perform globbing on this word. */
#define W_NOSPLIT2 0x0040 /* Don't split word except for $@ expansion. */
#define W_TILDEEXP 0x0080 /* Tilde expand this assignment word */
#define W_DOLLARAT 0x0100 /* $@ and its special handling */
#define W_DOLLARSTAR 0x0200 /* $* and its special handling */
#define W_NOCOMSUB 0x0400 /* Don't perform command substitution on this word */
#define W_HASDOLLAR 0x00001 /* Dollar sign present. */
#define W_QUOTED 0x00002 /* Some form of quote character is present. */
#define W_ASSIGNMENT 0x00004 /* This word is a variable assignment. */
#define W_GLOBEXP 0x00008 /* This word is the result of a glob expansion. */
#define W_NOSPLIT 0x00010 /* Do not perform word splitting on this word. */
#define W_NOGLOB 0x00020 /* Do not perform globbing on this word. */
#define W_NOSPLIT2 0x00040 /* Don't split word except for $@ expansion. */
#define W_TILDEEXP 0x00080 /* Tilde expand this assignment word */
#define W_DOLLARAT 0x00100 /* $@ and its special handling */
#define W_DOLLARSTAR 0x00200 /* $* and its special handling */
#define W_NOCOMSUB 0x00400 /* Don't perform command substitution on this word */
#define W_ASSIGNRHS 0x00800 /* Word is rhs of an assignment statement */
#define W_NOTILDE 0x01000 /* Don't perform tilde expansion on this word */
#define W_ITILDE 0x02000 /* Internal flag for word expansion */
#define W_NOEXPAND 0x04000 /* Don't expand at all -- do quote removal */
#define W_COMPASSIGN 0x08000 /* Compound assignment */
#define W_ASSNBLTIN 0x10000 /* word is a builtin command that takes assignments */
#define W_ASSIGNARG 0x20000 /* word is assignment argument to command */
#define W_HASQUOTEDNULL 0x40000 /* word contains a quoted null character */
#define W_DQUOTE 0x80000 /* word should be treated as if double-quoted */
/* Possible values for subshell_environment */
#define SUBSHELL_ASYNC 0x01 /* subshell caused by `command &' */
@ -193,6 +202,7 @@ typedef struct pattern_list {
struct pattern_list *next; /* Clause to try in case this one failed. */
WORD_LIST *patterns; /* Linked list of patterns to test. */
COMMAND *action; /* Thing to execute if a pattern matches. */
int flags;
} PATTERN_LIST;
/* The CASE command. */

View file

@ -47,7 +47,7 @@
/* Define DONT_REPORT_SIGPIPE if you don't want to see `Broken pipe' messages
when a job like `cat jobs.c | exit 1' is executed. */
/* #define DONT_REPORT_SIGPIPE */
#define DONT_REPORT_SIGPIPE
/* The default value of the PATH variable. */
#ifndef DEFAULT_PATH_VALUE

View file

@ -144,6 +144,10 @@
bash debugger. */
#undef DEBUGGER
/* Define STRICT_POSIX if you want bash to be strictly posix.2 conformant by
default (except for echo; that is controlled separately). */
#undef STRICT_POSIX
/* Define MEMSCRAMBLE if you want the bash malloc and free to scramble
memory contents on malloc() and free(). */
#undef MEMSCRAMBLE
@ -386,7 +390,6 @@
#undef HAVE_LIBC_FNM_EXTMATCH
#undef HAVE_DECL_CONFSTR
#undef HAVE_DECL_PRINTF
@ -403,6 +406,9 @@
#undef HAVE_MBSTATE_T
/* Define if WCONTINUED is defined in system headers, but rejected by waitpid */
#undef WCONTINUED_BROKEN
/* These are checked with BASH_CHECK_DECL */
#undef HAVE_DECL_STRTOIMAX
@ -508,6 +514,9 @@
/* Define if you have the dup2 function. */
#undef HAVE_DUP2
/* Define if you have the fcntl function. */
#undef HAVE_FCNTL
/* Define if you have the getaddrinfo function. */
#undef HAVE_GETADDRINFO
@ -532,6 +541,15 @@
/* Define if you have the getpeername function. */
#undef HAVE_GETPEERNAME
/* Define if you have the getpwent function. */
#undef HAVE_GETPWENT
/* Define if you have the getpwnam function. */
#undef HAVE_GETPWNAM
/* Define if you have the getpwuid function. */
#undef HAVE_GETPWUID
/* Define if you have the getrlimit function. */
#undef HAVE_GETRLIMIT
@ -574,6 +592,9 @@
/* Define if you have the isxdigit function. */
#undef HAVE_ISXDIGIT
/* Define if you have the kill function. */
#undef HAVE_KILL
/* Define if you have the killpg function. */
#undef HAVE_KILLPG
@ -604,6 +625,9 @@
/* Define if you have the putenv function. */
#undef HAVE_PUTENV
/* Define if you have the raise function. */
#undef HAVE_RAISE
/* Define if you have the readlink function. */
#undef HAVE_READLINK
@ -664,6 +688,9 @@
/* Define if you have the strftime function. */
#undef HAVE_STRFTIME
/* Define if you have the strnlen function. */
#undef HAVE_STRNLEN
/* Define if you have the strpbrk function. */
#undef HAVE_STRPBRK
@ -783,6 +810,9 @@
/* Define if you have the <netinet/in.h> header file. */
#undef HAVE_NETINET_IN_H
/* Define if you have the <pwd.h> header file. */
#undef HAVE_PWD_H
/* Define if you have the <regex.h> header file. */
#undef HAVE_REGEX_H

6821
configure vendored

File diff suppressed because it is too large Load diff

View file

@ -1,11 +1,11 @@
dnl
dnl Configure script for bash-3.0
dnl Configure script for bash-3.1
dnl
dnl report bugs to chet@po.cwru.edu
dnl
dnl Process this file with autoconf to produce a configure script.
# Copyright (C) 1987-2004 Free Software Foundation, Inc.
# Copyright (C) 1987-2005 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
@ -22,9 +22,9 @@ dnl Process this file with autoconf to produce a configure script.
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
# 02111-1307, USA.
AC_REVISION([for Bash 3.0, version 3.166, from autoconf version] AC_ACVERSION)dnl
AC_REVISION([for Bash 3.1, version 3.183])dnl
define(bashvers, 3.0)
define(bashvers, 3.1)
define(relstatus, release)
AC_INIT(bash, bashvers-relstatus, bug-bash@gnu.org)
@ -73,7 +73,7 @@ sparc-netbsd*) opt_bash_malloc=no ;; # needs 8-byte alignment
mips-irix6*) opt_bash_malloc=no ;; # needs 8-byte alignment
m68k-sysv) opt_bash_malloc=no ;; # fixes file descriptor leak in closedir
sparc-linux*) opt_bash_malloc=no ;; # sparc running linux; requires ELF
*-freebsd*-gnu) opt_bash_malloc=no ;; # there's some undetermined problem here
#*-freebsd*-gnu) opt_bash_malloc=no ;; # there's some undetermined problem here
#*-freebsd*) opt_bash_malloc=no ;; # they claim it's better; I disagree
*-openbsd*) opt_bash_malloc=no ;; # they claim it needs eight-bit alignment
*-aix*) opt_bash_malloc=no ;; # AIX machines
@ -82,7 +82,7 @@ sparc-linux*) opt_bash_malloc=no ;; # sparc running linux; requires ELF
*-rhapsody*) opt_bash_malloc=no ;; # Apple Rhapsody (MacOS X)
*-darwin*) opt_bash_malloc=no ;; # Apple Darwin (MacOS X)
*-dgux*) opt_bash_malloc=no ;; # DG/UX machines
*-qnx*) opt_bash_malloc=no ;; # QNX 4.2
*-qnx*) opt_bash_malloc=no ;; # QNX 4.2, QNX 6.x
*-machten4) opt_bash_malloc=no ;; # MachTen 4.x
*-bsdi2.1|*-bsdi3.?) opt_bash_malloc=no ; : ${CC:=shlicc2} ;; # for loadable builtins
*-beos*) opt_bash_malloc=no ;; # they say it's suitable
@ -173,6 +173,7 @@ opt_brace_expansion=yes
opt_disabled_builtins=no
opt_command_timing=yes
opt_xpg_echo=no
opt_strict_posix=no
opt_cond_command=yes
opt_cond_regexp=yes
opt_arith_for_command=yes
@ -181,6 +182,7 @@ opt_progcomp=yes
opt_separate_help=no
opt_multibyte=yes
opt_debugger=yes
opt_single_longdoc_strings=yes
dnl options that affect how bash is compiled and linked
opt_static_link=no
@ -227,6 +229,8 @@ AC_ARG_ENABLE(readline, AC_HELP_STRING([--enable-readline], [turn on command lin
AC_ARG_ENABLE(restricted, AC_HELP_STRING([--enable-restricted], [enable a restricted shell]), opt_restricted=$enableval)
AC_ARG_ENABLE(select, AC_HELP_STRING([--enable-select], [include select command]), opt_select=$enableval)
AC_ARG_ENABLE(separate-helpfiles, AC_HELP_STRING([--enable-separate-helpfiles], [use external files for help builtin documentation]), opt_separate_help=$enableval)
AC_ARG_ENABLE(single-help-strings, AC_HELP_STRING([--enable-single-help-strings], [store help documentation as a single string to ease translation]), opt_single_longdoc_strings=$enableval)
AC_ARG_ENABLE(strict-posix-default, AC_HELP_STRING([--enable-strict-posix-default], [configure bash to be posix-conformant by default]), opt_strict_posix=$enableval)
AC_ARG_ENABLE(usg-echo-default, AC_HELP_STRING([--enable-usg-echo-default], [a synonym for --enable-xpg-echo-default]), opt_xpg_echo=$enableval)
AC_ARG_ENABLE(xpg-echo-default, AC_HELP_STRING([--enable-xpg-echo-default], [make the echo builtin expand escape sequences by default]), opt_xpg_echo=$enableval)
@ -280,6 +284,9 @@ fi
if test $opt_xpg_echo = yes ; then
AC_DEFINE(DEFAULT_ECHO_TO_XPG)
fi
if test $opt_strict_posix = yes; then
AC_DEFINE(STRICT_POSIX)
fi
if test $opt_extended_glob = yes ; then
AC_DEFINE(EXTENDED_GLOB)
fi
@ -325,6 +332,10 @@ if test "$opt_separate_help" != no; then
HELPDIRDEFINE='-H ${HELPDIR}'
HELPINSTALL='install-help'
fi
HELPSTRINGS=
if test "$opt_single_longdoc_strings" != "yes"; then
HELPSTRINGS='-S'
fi
dnl now substitute in the values generated by arguments
AC_SUBST(TESTSCRIPT)
@ -342,6 +353,7 @@ AC_SUBST(htmldir)
AC_SUBST(HELPDIR)
AC_SUBST(HELPDIRDEFINE)
AC_SUBST(HELPINSTALL)
AC_SUBST(HELPSTRINGS)
echo ""
echo "Beginning configuration for bash-$BASHVERS-$RELSTATUS for ${host_cpu}-${host_vendor}-${host_os}"
@ -356,13 +368,10 @@ dnl test for Unix variants
AC_ISC_POSIX
AC_MINIX
dnl test for non-Unix variants
AC_CYGWIN
AC_MINGW32
AC_SYS_LARGEFILE
dnl BEGIN changes for cross-building for cygwin and BeOS
dnl BEGIN changes for cross-building (currently cygwin, minGW, and
dnl (obsolete) BeOS)
SIGNAMES_H=lsignames.h
@ -379,6 +388,9 @@ if test "x$cross_compiling" = "xyes"; then
cross_cache=${srcdir}/cross-build/cygwin32.cache
SIGNAMES_H='$(srcdir)/cross-build/win32sig.h'
;;
*-mingw*)
cross_cache=${srcdir}/cross-build/cygwin32.cache
;;
i[[3456]]86-*-beos*)
cross_cache=${srcdir}/cross-build/x86-beos.cache
SIGNAMES_H='${srcdir}/cross-build/beos-sig.h'
@ -391,6 +403,8 @@ if test "x$cross_compiling" = "xyes"; then
. ${cross_cache}
fi
unset cross_cache
CROSS_COMPILE='-DCROSS_COMPILING'
AC_SUBST(CROSS_COMPILE)
fi
AC_SUBST(SIGNAMES_H)
@ -475,9 +489,9 @@ then
esac
fi
TILDE_LIB=-ltilde
if test $opt_readline = yes; then
AC_DEFINE(READLINE)
READLINE_LIB=-lreadline
if test "$opt_with_installed_readline" != "no" ; then
case "$opt_with_installed_readline" in
yes) RL_INCLUDE= ;;
@ -488,9 +502,23 @@ if test $opt_readline = yes; then
;;
esac
READLINE_DEP=
READLINE_LIB=-lreadline
# section for OS versions that don't allow unresolved symbols
# to be compiled into dynamic libraries.
case "$host_os" in
cygwin*) TILDE_LIB= ;;
esac
else
RL_LIBDIR='$(dot)/$(LIBSUBDIR)/readline'
READLINE_DEP='$(READLINE_LIBRARY)'
# section for OS versions that ship an older/broken version of
# readline as a standard dynamic library and don't allow a
# static version specified as -llibname to override the
# dynamic version
case "${host_os}" in
darwin8*) READLINE_LIB='${READLINE_LIBRARY}' ;;
*) READLINE_LIB=-lreadline ;;
esac
fi
else
RL_LIBDIR='$(dot)/$(LIBSUBDIR)/readline'
@ -503,10 +531,10 @@ if test $opt_history = yes || test $opt_bang_history = yes; then
if test $opt_bang_history = yes; then
AC_DEFINE(BANG_HISTORY)
fi
HISTORY_LIB=-lhistory
if test "$opt_with_installed_readline" != "no"; then
HIST_LIBDIR=$RL_LIBDIR
HISTORY_DEP=
HISTORY_LIB=-lhistory
case "$opt_with_installed_readline" in
yes) RL_INCLUDE= ;;
*) case "$RL_INCLUDEDIR" in
@ -518,6 +546,14 @@ if test $opt_history = yes || test $opt_bang_history = yes; then
else
HIST_LIBDIR='$(dot)/$(LIBSUBDIR)/readline'
HISTORY_DEP='$(HISTORY_LIBRARY)'
# section for OS versions that ship an older version of
# readline as a standard dynamic library and don't allow a
# static version specified as -llibname to override the
# dynamic version
case "${host_os}" in
darwin8*) HISTORY_LIB='${HISTORY_LIBRARY}' ;;
*) HISTORY_LIB=-lhistory ;;
esac
fi
else
HIST_LIBDIR='$(dot)/$(LIBSUBDIR)/readline'
@ -531,6 +567,7 @@ AC_SUBST(RL_INCLUDE)
AC_SUBST(HISTORY_LIB)
AC_SUBST(HISTORY_DEP)
AC_SUBST(HIST_LIBDIR)
AC_SUBST(TILDE_LIB)
dnl END READLINE and HISTORY LIBRARY SECTION
@ -550,6 +587,28 @@ opennt*|interix*) MAKE_SHELL="$INTERIX_ROOT/bin/sh" ;;
esac
AC_SUBST(MAKE_SHELL)
dnl this is similar to the expanded AC_PROG_RANLIB
if test x$SIZE = x; then
if test x$ac_tool_prefix = x; then
SIZE=size
else
SIZE=${ac_tool_prefix}size
save_IFS=$IFS ; IFS=:
size_found=0
for dir in $PATH; do
if test -x $dir/$SIZE ; then
size_found=1
break
fi
done
if test $size_found -eq 0; then
SIZE=:
fi
IFS=$save_IFS
fi
fi
AC_SUBST(SIZE)
dnl Turn on any extensions available in the GNU C library.
AC_DEFINE(_GNU_SOURCE, 1)
@ -573,12 +632,20 @@ 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 grp.h strings.h regex.h)
AC_CHECK_HEADERS(sys/ptem.h sys/pte.h sys/stream.h sys/select.h sys/file.h \
stddef.h stdint.h netdb.h pwd.h grp.h strings.h regex.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)
AC_CHECK_HEADERS(netinet/in.h arpa/inet.h)
dnl sys/ptem.h requires definitions from sys/stream.h on systems where it
dnl exists
AC_CHECK_HEADER(sys/ptem.h, , ,[[
#if HAVE_SYS_STREAM_H
# include <sys/stream.h>
#endif
]])
dnl special checks for libc functions
AC_FUNC_ALLOCA
AC_FUNC_GETPGRP
@ -625,20 +692,23 @@ dnl checks for missing libc functions
AC_CHECK_FUNC(mkfifo,AC_DEFINE(HAVE_MKFIFO),AC_DEFINE(MKFIFO_MISSING))
dnl checks for system calls
AC_CHECK_FUNCS(dup2 select getdtablesize getgroups gethostname \
setdtablesize getpagesize killpg lstat getpeername sbrk \
getrlimit getrusage gettimeofday waitpid tcgetpgrp \
readlink)
AC_CHECK_FUNCS(dup2 fcntl getdtablesize getgroups gethostname getpagesize \
getpeername getrlimit getrusage gettimeofday kill killpg \
lstat readlink sbrk select setdtablesize tcgetpgrp uname \
ulimit waitpid)
AC_REPLACE_FUNCS(rename)
dnl checks for c library functions
AC_CHECK_FUNCS(bcopy bzero confstr sysconf pathconf setenv putenv unsetenv \
setlinebuf setvbuf setlocale strchr tcgetattr uname \
ulimit tzset siginterrupt memmove ttyname times \
AC_CHECK_FUNCS(bcopy bzero confstr fnmatch \
getaddrinfo gethostbyname getservbyname getservent inet_aton \
vsnprintf snprintf vasprintf asprintf fnmatch regcomp regexec)
memmove pathconf putenv raise regcomp regexec \
setenv setlinebuf setlocale setvbuf siginterrupt strchr \
sysconf tcgetattr times ttyname tzset unsetenv)
AC_CHECK_FUNCS(vsnprintf snprintf vasprintf asprintf)
AC_CHECK_FUNCS(isascii isblank isgraph isprint isspace isxdigit)
AC_REPLACE_FUNCS(getcwd strcasecmp strerror strftime strpbrk memset strstr)
AC_CHECK_FUNCS(getpwent getpwnam getpwuid)
AC_REPLACE_FUNCS(getcwd memset strcasecmp strerror strftime strnlen strpbrk strstr)
AC_REPLACE_FUNCS(strtod strtol strtoul strtoll strtoull strtoimax strtoumax)
AC_CHECK_DECLS([confstr])
@ -852,6 +922,8 @@ AC_HEADER_TIOCGWINSZ
BASH_HAVE_TIOCSTAT
BASH_HAVE_FIONREAD
BASH_CHECK_WCONTINUED
dnl miscellaneous
BASH_CHECK_SPEED_T
BASH_CHECK_GETPW_FUNCS
@ -917,11 +989,15 @@ sco3.2*) LOCAL_CFLAGS=-DMUST_UNBLOCK_CHLD ;;
sunos4*) LOCAL_CFLAGS=-DSunOS4 ;;
solaris2.5*) LOCAL_CFLAGS=-DSunOS5 ;;
lynxos*) LOCAL_CFLAGS=-DRECYCLES_PIDS ;;
linux*) LOCAL_LDFLAGS=-rdynamic ;; # allow dynamic loading
linux*) LOCAL_LDFLAGS=-rdynamic # allow dynamic loading
case "`uname -r`" in
2.[[456789]]*|3*) AC_DEFINE(PGRP_PIPE) ;;
esac ;;
*qnx6*) LOCAL_CFLAGS="-Dqnx -Dqnx6" LOCAL_LIBS="-lncurses" ;;
*qnx*) LOCAL_CFLAGS="-Dqnx -F -3s" LOCAL_LDFLAGS="-3s" LOCAL_LIBS="-lunix -lncurses" ;;
powerux*) LOCAL_LIBS="-lgen" ;;
cygwin*) LOCAL_CFLAGS=-DRECYCLES_PIDS ;;
opennt*|interix*) LOCAL_CFLAGS="-DNO_MAIN_ENV_ARG -DBROKEN_DIRENT_D_INO" ;;
opennt*|interix*) LOCAL_CFLAGS="-DNO_MAIN_ENV_ARG -DBROKEN_DIRENT_D_INO -D_POSIX_SOURCE" ;;
esac
dnl Stanza for OS/compiler pair-specific flags
@ -938,6 +1014,7 @@ freebsd[[3-9]]*)
LOCAL_LDFLAGS=-rdynamic # allow dynamic loading
fi ;;
freebsdelf*) LOCAL_LDFLAGS=-rdynamic ;; # allow dynamic loading
dragonfly*) LOCAL_LDFLAGS=-rdynamic ;; # allow dynamic loading
esac
case "$host_cpu" in
@ -987,6 +1064,10 @@ case "$srcdir" in
esac
BUILD_DIR=`pwd`
case "$BUILD_DIR" in
*\ *) BUILD_DIR=`echo "$BUILD_DIR" | sed 's: :\\\\ :g'` ;;
*) ;;
esac
AC_SUBST(PROFILE_FLAGS)

View file

@ -24,7 +24,7 @@
/* Placeholder for future modifications if cross-compiling or building a
`fat' binary, e.g. on Apple Rhapsody. These values are used in multiple
files, so they appear here. */
#if !defined (RHAPSODY)
#if !defined (RHAPSODY) && !defined (MACOSX)
# define HOSTTYPE CONF_HOSTTYPE
# define OSTYPE CONF_OSTYPE
# define MACHTYPE CONF_MACHTYPE

View file

@ -1,6 +1,6 @@
/* dispose_command.c -- dispose of a COMMAND structure. */
/* Copyright (C) 1987,1991 Free Software Foundation, Inc.
/* Copyright (C) 1987-2005 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@ -239,11 +239,16 @@ dispose_word (w)
WORD_DESC *w;
{
FREE (w->word);
#if 0
free (w);
#else
ocache_free (wdcache, WORD_DESC, w);
#endif
}
/* Free a WORD_DESC, but not the word contained within. */
void
dispose_word_desc (w)
WORD_DESC *w;
{
w->word = 0;
ocache_free (wdcache, WORD_DESC, w);
}
/* How to get rid of a linked list of words. A WORD_LIST. */

View file

@ -1,6 +1,6 @@
/* dispose_cmd.h -- Functions appearing in dispose_cmd.c. */
/* Copyright (C) 1993 Free Software Foundation, Inc.
/* Copyright (C) 1993-2005 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@ -24,6 +24,7 @@
#include "stdc.h"
extern void dispose_command __P((COMMAND *));
extern void dispose_word_desc __P((WORD_DESC *));
extern void dispose_word __P((WORD_DESC *));
extern void dispose_words __P((WORD_LIST *));
extern void dispose_word_array __P((char **));

103
doc/FAQ
View file

@ -1,4 +1,4 @@
This is the Bash FAQ, version 3.27, for Bash version 3.0.
This is the Bash FAQ, version 3.32, for Bash version 3.1.
This document contains a set of frequently-asked questions concerning
Bash, the GNU Bourne-Again Shell. Bash is a freely-available command
@ -36,9 +36,9 @@ A10) What is the bash `posix mode'?
Section B: The latest version
B1) What's new in version 3.0?
B2) Are there any user-visible incompatibilities between bash-3.0 and
bash-1.14.7?
B1) What's new in version 3.1?
B2) Are there any user-visible incompatibilities between bash-3.1 and
bash-2.05b?
Section C: Differences from other Unix shells
@ -140,22 +140,26 @@ of Case Western Reserve University.
A2) What's the latest version?
The latest version is 3.0, first made available on 27 July, 2004.
The latest version is 3.1, first made available on 09 December, 2005.
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 3.0:
The following URLs tell how to get version 3.1:
ftp://ftp.gnu.org/pub/gnu/bash/bash-3.0.tar.gz
ftp://ftp.cwru.edu/pub/bash/bash-3.0.tar.gz
ftp://ftp.gnu.org/pub/gnu/bash/bash-3.1.tar.gz
ftp://ftp.cwru.edu/pub/bash/bash-3.1.tar.gz
Formatted versions of the documentation are available with the URLs:
ftp://ftp.gnu.org/pub/gnu/bash/bash-doc-3.0.tar.gz
ftp://ftp.cwru.edu/pub/bash/bash-doc-3.0.tar.gz
ftp://ftp.gnu.org/pub/gnu/bash/bash-doc-3.1.tar.gz
ftp://ftp.cwru.edu/pub/bash/bash-doc-3.1.tar.gz
Any patches for the current version are available with the URL:
ftp://ftp.cwru.edu/pub/bash/bash-3.1-patches/
A4) On what machines will bash run?
@ -181,16 +185,15 @@ earlier Minix versions yet.
Bash has been ported to versions of Windows implementing the Win32
programming interface. This includes Windows 95 and Windows NT.
The port was done by Cygnus Solutions as part of their CYGWIN
project. For more information about the project, look at the URLs
http://www.cygwin.com/
http://sourceware.cygnus.com/cygwin
The port was done by Cygnus Solutions (now part of Red Hat) as part
of their CYGWIN project. For more information about the project, see
http://www.cygwin.com/.
Cygnus originally ported bash-1.14.7, and that port was part of their
early GNU-Win32 (the original name) releases. Cygnus has also done a
port of bash-2.05 to the CYGWIN environment, and it is available as
part of their current release.
early GNU-Win32 (the original name) releases. Cygnus has also done
ports of bash-2.05b and bash-3.0 to the CYGWIN environment, and both
are available as part of their current release. Bash-3.1 is currently
being tested and should be available soon.
Bash-2.05b and later versions should require no local Cygnus changes to
build and run under CYGWIN.
@ -212,7 +215,8 @@ ftp://ftp.simtel.net/pub/simtelnet/gnu/djgpp/v2gnu/bsh204s.zip source
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.
for Unix (SFU), once known as Interix. I do not anticipate any problems
with building bash-3.1.
A6) How can I build bash with gcc?
@ -381,15 +385,25 @@ They are also listed in a section in the Bash Reference Manual
Section B: The latest version
B1) What's new in version 3.0?
B1) What's new in version 3.1?
Bash-3.0 is the third major release of bash. The features introduced
in the intermediate releases following bash-2.05 have been completed.
Support for the bash debugger (a separate project) has been integrated.
Bash-3.1 is the first maintenance release of the third major release of
bash. It contains the following significant new features (see the manual
page for complete descriptions and the CHANGES and NEWS files in the
bash-3.1 distribution).
Bash-3.0 contains the following new features (see the manual page for
complete descriptions and the CHANGES and NEWS files in the bash-3.0
distribution):
o Bash-3.1 may now be configured and built in a mode that enforces strict
POSIX compliance.
o The `+=' assignment operator, which appends to the value of a string or
array variable, has been implemented.
o It is now possible to ignore case when matching in contexts other than
filename generation using the new `nocasematch' shell option.
A short feature history dating from Bash-2.0:
Bash-3.0 contained the following new features:
o Features to support the bash debugger have been implemented, and there
is a new `extdebug' option to turn the non-default options on
@ -419,8 +433,6 @@ o The `jobs', `kill', and `wait' builtins now accept job control notation
o The `gettext' package and libintl have been integrated, and the shell
messages may be translated into other languages
A short feature history dating from Bash-2.0:
Bash-2.05b introduced the following new features:
o support for multibyte characters has been added to both bash and readline
@ -628,10 +640,10 @@ 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-3.0 and
bash-1.14.7?
B2) Are there any user-visible incompatibilities between bash-3.1 and
bash-2.05b?
There are a few incompatibilities between version 1.14.7 and version 3.0.
There are a few incompatibilities between version 2.05b and version 3.1.
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
if if you find something that's not mentioned there.
@ -714,11 +726,12 @@ Things bash has that sh does not:
case-insensitive pattern matching and globbing
variable assignments preceding commands affect only that command,
even for builtins and functions
posix mode
posix mode and strict posix conformance
redirection to /dev/fd/N, /dev/stdin, /dev/stdout, /dev/stderr,
/dev/tcp/host/port, /dev/udp/host/port
debugger support, including `caller' builtin and new variables
RETURN trap
the `+=' assignment operator
Things sh has that bash does not:
@ -796,6 +809,7 @@ Things bash has or uses that ksh88 does not:
RETURN trap
Timestamps in history entries
{x..y} brace expansion
The `+=' assignment operator
Things ksh88 has or uses that bash does not:
tracked aliases (alias -t)
@ -842,7 +856,6 @@ New things in ksh-93 not in bash-3.0:
`fc' has been renamed to `hist'
`.' can execute shell functions
exit statuses between 0 and 255
`+=' variable assignment operator
FPATH and PATH mixing
getopts -a
-I invocation option
@ -876,6 +889,7 @@ New things in ksh-93 present in bash-3.0:
command name completion
ENV processed only for interactive shells
set -o pipefail
The `+=' assignment operator
Section D: Why does bash do some things differently than other Unix shells?
@ -1099,9 +1113,8 @@ will try to write on a pipe without a reader. In that case, bash
will print `Broken pipe' to stderr when ps is killed by a
SIGPIPE.
You can build a version of bash that will not report SIGPIPE errors
by uncommenting the definition of DONT_REPORT_SIGPIPE in the file
config-top.h.
As of bash-3.1, bash will not report SIGPIPE errors by default. You
can build a version of bash that will report such errors.
E3) When I have terminal escape sequences in my prompt, why does bash
wrap lines at the wrong column?
@ -1128,12 +1141,12 @@ simple calls to `read'. For example, piping a command's output
into a `while' loop that repeatedly calls `read' will result in
the same behavior.
Each element of a pipeline runs in a separate process, a child of
the shell running the pipeline. A subprocess cannot affect its
parent's environment. When the `read' command sets the variable
to the input, that variable is set only in the subshell, not the
parent shell. When the subshell exits, the value of the variable
is lost.
Each element of a pipeline, even a builtin or shell function,
runs in a separate process, a child of the shell running the
pipeline. A subprocess cannot affect its parent's environment.
When the `read' command sets the variable to the input, that
variable is set only in the subshell, not the parent shell. When
the subshell exits, the value of the variable is lost.
Many pipelines that end with `read variable' can be converted
into command substitutions, which will capture the output of
@ -1763,21 +1776,19 @@ These are features that may or may not appear in a future version of bash.
breaking some of the shell functionality into embeddable libraries
a module system like zsh's, using dynamic loading like builtins
date-stamped command history
a bash programmer's guide with a chapter on creating loadable builtins
a better loadable interface to perl with access to the shell builtins and
variables (contributions gratefully accepted)
ksh93-like `nameref' variables
ksh93-like `+=' variable assignment operator
ksh93-like `xx.yy' variables (including some of the .sh.* variables) and
associated disipline functions
Some of the new ksh93 pattern matching operators, like backreferencing
H5) When will the next release appear?
The next version will appear sometime in 2005. Never make predictions.
The next version will appear sometime in 2006. Never make predictions.
This document is Copyright 1995-2004 by Chester Ramey.
This document is Copyright 1995-2005 by Chester Ramey.
Permission is hereby granted, without written agreement and
without license or royalty fees, to use, copy, and distribute

1418
doc/article.ps Normal file

File diff suppressed because it is too large Load diff

View file

@ -1,17 +1,17 @@
.\"
\"
.\" MAN PAGE COMMENTS to
.\"
.\" Chet Ramey
.\" Information Network Services
.\" Case Western Reserve University
.\" chet@po.CWRU.Edu
.\" chet@po.cwru.edu
.\"
.\" Last Change: Sat Jun 26 14:26:44 EDT 2004
.\" Last Change: Sat Aug 27 13:28:44 EDT 2005
.\"
.\" bash_builtins, strip all but Built-Ins section
.if \n(zZ=1 .ig zZ
.if \n(zY=1 .ig zY
.TH BASH 1 "2004 June 26" "GNU Bash-3.0"
.TH BASH 1 "2005 Aug 27" "GNU Bash-3.1-beta1"
.\"
.\" There's some problem with having a `@'
.\" in a tagged paragraph with the BSD man macros.
@ -51,8 +51,8 @@ bash \- GNU Bourne-Again SHell
[options]
[file]
.SH COPYRIGHT
.if n Bash is Copyright (C) 1989-2004 by the Free Software Foundation, Inc.
.if t Bash is Copyright \(co 1989-2004 by the Free Software Foundation, Inc.
.if n Bash is Copyright (C) 1989-2005 by the Free Software Foundation, Inc.
.if t Bash is Copyright \(co 1989-2005 by the Free Software Foundation, Inc.
.SH DESCRIPTION
.B Bash
is an \fBsh\fR-compatible command language interpreter that
@ -64,6 +64,8 @@ shells (\fBksh\fP and \fBcsh\fP).
.B Bash
is intended to be a conformant implementation of the IEEE
POSIX Shell and Tools specification (IEEE Working Group 1003\.2).
.B Bash
can be configured to be POSIX-conformant by default.
.SH OPTIONS
In addition to the single-character shell options documented in the
description of the \fBset\fR builtin command, \fBbash\fR
@ -115,7 +117,7 @@ when invoking an interactive shell.
.TP
.B \-D
A list of all double-quoted strings preceded by \fB$\fP
is printed on the standard ouput.
is printed on the standard output.
These are the strings that
are subject to language translation when the current locale
is not \fBC\fP or \fBPOSIX\fP.
@ -154,11 +156,13 @@ single-character options to be recognized.
.TP
.B \-\-debugger
Arrange for the debugger profile to be executed before the shell
starts. Turns on extended debugging mode (see the description of the
starts.
Turns on extended debugging mode (see the description of the
.B extdebug
option to the
.B shopt
builtin below) and shell function tracing (see the description of the
builtin below)
and shell function tracing (see the description of the
\fB\-o functrace\fP option to the
.B set
builtin below).
@ -669,6 +673,10 @@ as primaries.
When the \fB==\fP and \fB!=\fP operators are used, the string to the
right of the operator is considered a pattern and matched according
to the rules described below under \fBPattern Matching\fP.
If the shell option
.B nocasematch
is enabled, the match is performed without regard to the case
of alphabetic characters.
The return value is 0 if the string matches or does not match
the pattern, respectively, and 1 otherwise.
Any part of the pattern may be quoted to force it to be matched as a
@ -684,7 +692,7 @@ the pattern, and 1 otherwise.
If the regular expression is syntactically incorrect, the conditional
expression's return value is 2.
If the shell option
.B nocaseglob
.B nocasematch
is enabled, the match is performed without regard to the case
of alphabetic characters.
Substrings matched by parenthesized subexpressions within the regular
@ -798,7 +806,12 @@ A \fBcase\fP command first expands \fIword\fP, and tries to match
it against each \fIpattern\fP in turn, using the same matching rules
as for pathname expansion (see
.B Pathname Expansion
below). When a match is found, the
below).
If the shell option
.B nocasematch
is enabled, the match is performed without regard to the case
of alphabetic characters.
When a match is found, the
corresponding \fIlist\fP is executed. After the first match, no
subsequent matches are attempted. The exit status is zero if no
pattern matches. Otherwise, it is the exit status of the
@ -895,7 +908,11 @@ Each of the \fImetacharacters\fP listed above under
has special meaning to the shell and must be quoted if it is to
represent itself.
.PP
When the command history expansion facilities are being used, the
When the command history expansion facilities are being used
(see
.SM
.B HISTORY EXPANSION
below), the
\fIhistory expansion\fP character, usually \fB!\fP, must be quoted
to prevent history expansion.
.PP
@ -919,8 +936,9 @@ Enclosing characters in double quotes preserves the literal value
of all characters within the quotes, with the exception of
.BR $ ,
.BR ` ,
and
.BR \e .
.BR \e ,
and, when history expansion is enabled,
.BR ! .
The characters
.B $
and
@ -936,8 +954,12 @@ or
.BR <newline> .
A double quote may be quoted within double quotes by preceding it with
a backslash.
When command history is being used, the double quote may not be used to
quote the history expansion character.
If enabled, history expansion will be performed unless an
.B !
appearing in double quotes is escaped using a backslash.
The backslash preceding the
.B !
is not removed.
.PP
The special parameters
.B *
@ -951,7 +973,7 @@ below).
.PP
Words of the form \fB$\fP'\fIstring\fP' are treated specially. The
word expands to \fIstring\fP, with backslash-escaped characters replaced
as specifed by the ANSI C standard. Backslash escape sequences, if
as specified by the ANSI C standard. Backslash escape sequences, if
present, are decoded as follows:
.RS
.PD 0
@ -1076,6 +1098,20 @@ Assignment statements may also appear as arguments to the
and
.B local
builtin commands.
.PP
In the context where an assignment statement is assigning a value
to a shell variable or array index, the += operator can be used to
append to or add to the variable's previous value.
When += is applied to a variable for which the integer attribute has been
set, \fIvalue\fP is evaluated as an arithmetic expression and added to the
variable's current value, which is also evaluated.
When += is applied to an array variable using compound assignment (see
.B Arrays
below), the
variable's value is not unset (as it is when using =), and new values are
appended to the array beginning at one greater than the array's maximum index.
When applied to a string-valued variable, \fIvalue\fP is expanded and
appended to the variable's value.
.SS Positional Parameters
.PP
A
@ -1130,6 +1166,10 @@ Expands to the positional parameters, starting from one. When the
expansion occurs within double quotes, each parameter expands to a
separate word. That is, "\fB$@\fP" is equivalent to
"\fB$1\fP" "\fB$2\fP" ...
If the double-quoted expansion occurs within a word, the expansion of
the first parameter is joined with the beginning part of the original
word, and the expansion of the last parameter is joined with the last
part of the original word.
When there are no positional parameters, "\fB$@\fP" and
.B $@
expand to nothing (i.e., they are removed).
@ -1178,12 +1218,13 @@ to the file name used to invoke
as given by argument zero.
.TP
.B _
At shell startup, set to the absolute file name of the shell or shell
script being executed as passed in the argument list.
At shell startup, set to the absolute pathname used to invoke the
shell or shell script being executed as passed in the environment
or argument list.
Subsequently, expands to the last argument to the previous command,
after expansion.
Also set to the full file name of each command executed and placed in
the environment exported to that command.
Also set to the full pathname used to invoke each command executed
and placed in the environment exported to that command.
When checking mail, this parameter holds the name of the mail file
currently being checked.
.PD
@ -1199,11 +1240,18 @@ Expands to the full file name used to invoke this instance of
.TP
.B BASH_ARGC
An array variable whose values are the number of parameters in each
frame of the current bash execution call stack. The number of
frame of the current bash execution call stack.
The number of
parameters to the current subroutine (shell function or script executed
with \fB.\fP or \fBsource\fP) is at the top of the stack. When a
subroutine is executed, the number of parameters passed is pushed onto
with \fB.\fP or \fBsource\fP) is at the top of the stack.
When a subroutine is executed, the number of parameters passed is pushed onto
\fBBASH_ARGC\fP.
The shell sets \fBBASH_ARGC\fP only when in extended debugging mode
(see the description of the
.B extdebug
option to the
.B shopt
builtin below)
.TP
.B BASH_ARGV
An array variable containing all of the parameters in the current bash
@ -1211,6 +1259,12 @@ execution call stack. The final parameter of the last subroutine call
is at the top of the stack; the first parameter of the initial call is
at the bottom. When a subroutine is executed, the parameters supplied
are pushed onto \fBBASH_ARGV\fP.
The shell sets \fBBASH_ARGV\fP only when in extended debugging mode
(see the description of the
.B extdebug
option to the
.B shopt
builtin below)
.TP
.B BASH_COMMAND
The command currently being executed or about to be executed, unless the
@ -1222,10 +1276,10 @@ The command argument to the \fB\-c\fP invocation option.
.TP
.B BASH_LINENO
An array variable whose members are the line numbers in source files
corresponding to each member of @var{FUNCNAME}.
corresponding to each member of \fBFUNCNAME\fP.
\fB${BASH_LINENO[\fP\fI$i\fP\fB]}\fP is the line number in the source
file where \fB${FUNCNAME[\fP\fI$i + 1\fP\fB]}\fP was called.
The corresponding source file name is \fB${BASH_SOURCE[\fP\fI$i + 1\fP\fB]}\fB.
file where \fB${FUNCNAME[\fP\fI$ifP\fB]}\fP was called.
The corresponding source file name is \fB${BASH_SOURCE[\fP\fI$i\fP\fB]}\fB.
Use \fBLINENO\fP to obtain the current line number.
.TP
.B BASH_REMATCH
@ -1934,6 +1988,10 @@ number of seconds to wait for input after issuing the primary prompt.
terminates after waiting for that number of seconds if input does
not arrive.
.TP
.B TMPDIR
If set, \fBBash\fP uses its value as the name of a directory in which
\fBBash\fP creates temporary files for the shell's use.
.TP
.B auto_resume
This variable controls how the shell interacts with the user and
job control. If this variable is set, single word simple
@ -1959,9 +2017,7 @@ job identifier (see
.B JOB CONTROL
below). If set to any other value, the supplied string must
be a prefix of a stopped job's name; this provides functionality
analogous to the
.B %
job identifier.
analogous to the \fB%\fP\fIstring\fP job identifier.
.TP
.B histchars
The two or three characters which control history expansion
@ -2035,7 +2091,12 @@ character of the
.B IFS
special variable, and ${\fIname\fP[@]} expands each element of
\fIname\fP to a separate word. When there are no array members,
${\fIname\fP[@]} expands to nothing. This is analogous to the expansion
${\fIname\fP[@]} expands to nothing.
If the double-quoted expansion occurs within a word, the expansion of
the first parameter is joined with the beginning part of the original
word, and the expansion of the last parameter is joined with the last
part of the original word.
This is analogous to the expansion
of the special parameters \fB*\fP and \fB@\fP (see
.B Special Parameters
above). ${#\fIname\fP[\fIsubscript\fP]} expands to the length of
@ -2048,6 +2109,8 @@ The
.B unset
builtin is used to destroy arrays. \fBunset\fP \fIname\fP[\fIsubscript\fP]
destroys the array element at index \fIsubscript\fP.
Care must be taken to avoid unwanted side effects caused by filename
generation.
\fBunset\fP \fIname\fP, where \fIname\fP is an array, or
\fBunset\fP \fIname\fP[\fIsubscript\fP], where
\fIsubscript\fP is \fB*\fP or \fB@\fP, removes the entire array.
@ -2229,7 +2292,7 @@ is unchanged.
Each variable assignment is checked for unquoted tilde-prefixes immediately
following a
.B :
or
or the first
.BR = .
In these cases, tilde expansion is also performed.
Consequently, one may use file names with tildes in assignments to
@ -2252,7 +2315,7 @@ interpreted as part of the name.
.PP
When braces are used, the matching ending brace is the first `\fB}\fP'
not escaped by a backslash or within a quoted string, and not within an
embedded arithmetic expansion, command substitution, or paramter
embedded arithmetic expansion, command substitution, or parameter
expansion.
.PP
.PD 0
@ -2352,6 +2415,10 @@ parameters beginning at \fIoffset\fP.
If \fIparameter\fP is an array name indexed by @ or *,
the result is the \fIlength\fP
members of the array beginning with ${\fIparameter\fP[\fIoffset\fP]}.
A negative \fIoffset\fP is taken relative to one greater than the maximum
index of the specified array.
Note that a negative offset must be separated from the colon by at least
one space to avoid being confused with the :- expansion.
Substring indexing is zero-based unless the positional parameters
are used, in which case the indexing starts at 1.
.TP
@ -2846,7 +2913,7 @@ Matches zero or more occurrences of the given patterns
Matches one or more occurrences of the given patterns
.TP
\fB@(\fP\^\fIpattern-list\^\fP\fB)\fP
Matches exactly one of the given patterns
Matches one of the given patterns
.TP
\fB!(\fP\^\fIpattern-list\^\fP\fB)\fP
Matches anything except one of the given patterns
@ -2943,6 +3010,10 @@ a UDP connection to the corresponding socket.
.RE
.PP
A failure to open or create a file causes the redirection to fail.
.PP
Redirections using file descriptors greater than 9 should be used with
care, as they may conflict with file descriptors the shell uses
internally.
.SS Redirecting Input
.PP
Redirection of input causes the file whose name results from
@ -3291,19 +3362,21 @@ environment are identical between a function and its caller
with the exception that the
.SM
.B DEBUG
trap (see the description of the
and
.B RETURN
traps (see the description of the
.B trap
builtin under
.SM
.B SHELL BUILTIN COMMANDS
below) is not inherited unless the function has been given the
below) are not inherited unless the function has been given the
\fBtrace\fP attribute (see the description of the
.SM
.B declare
builtin below) or the
\fB\-o functrace\fP shell option has been enabled with
the \fBset\fP builtin
(in which case all functions inherit the \fBDEBUG\fP trap).
(in which case all functions inherit the \fBDEBUG\fP and \fBRETURN\fP traps).
.PP
Variables local to the function may be declared with the
.B local
@ -3442,7 +3515,7 @@ If \fIbase#\fP is omitted, then base 10 is used.
The digits greater than 9 are represented by the lowercase letters,
the uppercase letters, @, and _, in that order.
If \fIbase\fP is less than or equal to 36, lowercase and uppercase
letters may be used interchangably to represent numbers between 10
letters may be used interchangeably to represent numbers between 10
and 35.
.PP
Operators are evaluated in order of precedence. Sub-expressions in
@ -3458,6 +3531,9 @@ If any \fIfile\fP argument to one of the primaries is of the form
If the \fIfile\fP argument to one of the primaries is one of
\fI/dev/stdin\fP, \fI/dev/stdout\fP, or \fI/dev/stderr\fP, file
descriptor 0, 1, or 2, respectively, is checked.
.PP
Unless otherwise specified, primaries that operate on files follow symbolic
links and operate on the target of the link, rather than the link itself.
.sp 1
.PD 0
.TP
@ -3923,7 +3999,7 @@ sends a
.B SIGHUP
to all jobs when an interactive login shell exits.
.PP
If \Bbash\fP is waiting for a command to complete and receives a signal
If \fBbash\fP is waiting for a command to complete and receives a signal
for which a trap has been set, the trap will not be executed until
the command completes.
When \fBbash\fP is waiting for an asynchronous command via the \fBwait\fP
@ -4053,6 +4129,8 @@ command), the current job is always flagged with a
.BR + ,
and the previous job with a
.BR \- .
A single % (with no accompanying job specification) also refers to the
current job.
.PP
Simply naming a job can be used to bring it into the
foreground:
@ -4489,7 +4567,12 @@ file with a statement of the form
Except where noted, readline variables can take the values
.B On
or
.BR Off .
.B Off
(without regard to case).
Unrecognized variable names are ignored.
When a variable value is read, empty or null values, "on" (case-insensitive),
and "1" are equivalent to \fBOn\fP. All other values are equivalent to
\fBOff\fP.
The variables and their default values are:
.PP
.PD 0
@ -4500,6 +4583,11 @@ If set to \fBnone\fP, readline never rings the bell. If set to
\fBvisible\fP, readline uses a visible bell if one is available.
If set to \fBaudible\fP, readline attempts to ring the terminal's bell.
.TP
.B bind\-tty\-special\-chars (On)
If set to \fBOn\fP, readline attempts to bind the control characters
treated specially by the kernel's terminal driver to their readline
equivalents.
.TP
.B comment\-begin (``#'')
The string that is inserted when the readline
.B insert\-comment
@ -4553,9 +4641,9 @@ arrow keys.
If set to \fBon\fP, tilde expansion is performed when readline
attempts word completion.
.TP
.B history-preserve-point
.B history\-preserve\-point (Off)
If set to \fBon\fP, the history code attempts to place point at the
same location on each history line retrived with \fBprevious-history\fP
same location on each history line retrieved with \fBprevious-history\fP
or \fBnext-history\fP.
.TP
.B horizontal\-scroll\-mode (Off)
@ -4855,6 +4943,8 @@ With an argument
insert the \fIn\fPth word from the previous command (the words
in the previous command begin with word 0). A negative argument
inserts the \fIn\fPth word from the end of the previous command.
Once the argument \fIn\fP is computed, the argument is extracted
as if the "!\fIn\fP" history expansion had been specified.
.TP
.B
yank\-last\-arg (M\-.\^, M\-_\^)
@ -4863,6 +4953,8 @@ the previous history entry). With an argument,
behave exactly like \fByank\-nth\-arg\fP.
Successive calls to \fByank\-last\-arg\fP move back through the history
list, inserting the last argument of each line in turn.
The history expansion facilities are used to extract the last argument,
as if the "!$" history expansion had been specified.
.TP
.B shell\-expand\-line (M\-C\-e)
Expand the line as the shell does. This
@ -5275,7 +5367,7 @@ of an \fIinputrc\fP file.
.TP
.B dump\-macros
Print all of the readline key sequences bound to macros and the
strings they ouput. If a numeric argument is supplied,
strings they output. If a numeric argument is supplied,
the output is formatted in such a way that it can be made part
of an \fIinputrc\fP file.
.TP
@ -5339,7 +5431,7 @@ special variable as delimiters.
Shell quoting is honored.
Each word is then expanded using
brace expansion, tilde expansion, parameter and variable expansion,
command substitution, arithmetic expansion, and pathname expansion,
command substitution, and arithmetic expansion,
as described above under
.SM
.BR EXPANSION .
@ -5806,6 +5898,8 @@ section as accepting options preceded by
accepts
.B \-\-
to signify the end of the options.
For example, the \fB:\fP, \fBtrue\fP, \fBfalse\fP, and \fBtest\fP builtins
do not accept options.
.sp .5
.PD 0
.TP
@ -5872,8 +5966,8 @@ is supplied, the name and value of the alias is printed.
\fBAlias\fP returns true unless a \fIname\fP is given for which
no alias has been defined.
.TP
\fBbg\fP [\fIjobspec\fP]
Resume the suspended job \fIjobspec\fP in the background, as if it
\fBbg\fP [\fIjobspec\fP ...]
Resume each suspended job \fIjobspec\fP in the background, as if it
had been started with
.BR & .
If \fIjobspec\fP is not present, the shell's notion of the
@ -5881,8 +5975,8 @@ If \fIjobspec\fP is not present, the shell's notion of the
.B bg
.I jobspec
returns 0 unless run when job control is disabled or, when run with
job control enabled, if \fIjobspec\fP was not found or started without
job control.
job control enabled, any specified \fIjobspec\fP was not found
or was started without job control.
.TP
\fBbind\fP [\fB\-m\fP \fIkeymap\fP] [\fB\-lpsvPSV\fP]
.PD 0
@ -6174,6 +6268,11 @@ suppressing trailing spaces). Intended to be used with shell functions.
.B nospace
Tell readline not to append a space (the default) to words completed at
the end of the line.
.TP 8
.B plusdirs
After any matches defined by the compspec are generated,
directory name completion is attempted and any
matches are added to the results of the other actions.
.RE
.TP 8
\fB\-A\fP \fIaction\fP
@ -6376,7 +6475,8 @@ by subsequent assignment statements or unset.
.TP
.B \-t
Give each \fIname\fP the \fItrace\fP attribute.
Traced functions inherit the \fBDEBUG\fP trap from the calling shell.
Traced functions inherit the \fBDEBUG\fP and \fBRETURN\fP traps from
the calling shell.
The trace attribute has no special meaning for variables.
.TP
.B \-x
@ -6495,9 +6595,7 @@ The \fBxpg_echo\fP shell option may be used to
dynamically determine whether or not \fBecho\fP expands these
escape characters by default.
.B echo
does not interpret
.B \-\-
to mean the end of options.
does not interpret \fB\-\-\fP to mean the end of options.
.B echo
interprets the following escape sequences:
.RS
@ -7205,7 +7303,7 @@ is empty, a non-existent directory stack entry is specified, or the
directory change fails.
.RE
.TP
\fBprintf\fP \fIformat\fP [\fIarguments\fP]
\fBprintf\fP [\fB\-v\fP \fIvar\fP] \fIformat\fP [\fIarguments\fP]
Write the formatted \fIarguments\fP to the standard output under the
control of the \fIformat\fP.
The \fIformat\fP is a character string which contains three types of objects:
@ -7221,6 +7319,9 @@ beginning with \fB\e0\fP may contain up to four digits),
and \fB%q\fP causes \fBprintf\fP to output the corresponding
\fIargument\fP in a format that can be reused as shell input.
.sp 1
The \fB\-v\fP option causes the output to be assigned to the variable
\fIvar\fP rather than being printed to the standard output.
.sp 1
The \fIformat\fP is reused as necessary to consume all of the \fIarguments\fP.
If the \fIformat\fP requires more \fIarguments\fP than are supplied, the
extra format specifications behave as if a zero value or null string, as
@ -7366,7 +7467,7 @@ input is not read within \fItimeout\fP seconds.
This option has no effect if \fBread\fP is not reading input from the
terminal or a pipe.
.TP
.B \-u \fIfd\FP
.B \-u \fIfd\fP
Read input from file descriptor \fIfd\fP.
.PD
.PP
@ -7435,7 +7536,10 @@ before execution resumes after the function or script.
.TP
\fBset\fP [\fB\-\-abefhkmnptuvxBCHP\fP] [\fB\-o\fP \fIoption\fP] [\fIarg\fP ...]
Without options, the name and value of each shell variable are displayed
in a format that can be reused as input.
in a format that can be reused as input
for setting or resetting the currently-set variables.
Read-only variables cannot be reset.
In \fIposix mode\fP, only shell variables are listed.
The output is sorted according to the current locale.
When options are specified, they set or unset shell attributes.
Any arguments remaining after the options are processed are treated
@ -7608,7 +7712,7 @@ This option is disabled by default.
Change the behavior of
.B bash
where the default operation differs
from the POSIX 1003.2 standard to match the standard (\fI`posix mode\fP).
from the POSIX 1003.2 standard to match the standard (\fIposix mode\fP).
.TP 8
.B privileged
Same as
@ -7722,9 +7826,11 @@ follows the logical chain of directories when performing commands
which change the current directory.
.TP 8
.B \-T
If set, any trap on \fBDEBUG\fP is inherited by shell functions, command
substitutions, and commands executed in a subshell environment.
The \fBDEBUG\fP trap is normally not inherited in such cases.
If set, any traps on \fBDEBUG\fP and \fBRETURN\fP are inherited by shell
functions, command substitutions, and commands executed in a
subshell environment.
The \fBDEBUG\fP and \fBRETURN\fP traps are normally not inherited
in such cases.
.TP 8
.B \-\-
If no arguments follow this option, then the positional parameters are
@ -7904,6 +8010,20 @@ If the command run by the \fBDEBUG\fP trap returns a value of 2, and the
shell is executing in a subroutine (a shell function or a shell script
executed by the \fB.\fP or \fBsource\fP builtins), a call to
\fBreturn\fP is simulated.
.TP
.B 4.
\fBBASH_ARGC\fP and \fBBASH_ARGV\fP are updated as described in their
descriptions above.
.TP
.B 5.
Function tracing is enabled: command substitution, shell functions, and
subshells invoked with \fB(\fP \fIcommand\fP \fB)\fP inherit the
\fBDEBUG\fP and \fBRETURN\fP traps.
.TP
.B 6.
Error tracing is enabled: command substitution, shell functions, and
subshells invoked with \fB(\fP \fIcommand\fP \fB)\fP inherit the
\fBERROR\fP trap.
.RE
.TP 8
.B extglob
@ -8013,6 +8133,12 @@ expansion (see
.B Pathname Expansion
above).
.TP 8
.B nocasematch
If set,
.B bash
matches patterns in a case\-insensitive fashion when performing matching
while executing \fBcase\fP or \fB[[\fP conditional commands.
.TP 8
.B nullglob
If set,
.B bash
@ -8086,6 +8212,8 @@ Each operator and operand must be a separate argument.
Expressions are composed of the primaries described above under
.SM
.BR "CONDITIONAL EXPRESSIONS" .
\fBtest\fP does not accept any options, nor does it accept and ignore
an argument of \fB\-\-\fP as signifying the end of options.
.if t .sp 0.5
.if n .sp 1
Expressions may be combined using the following operators, listed
@ -8232,7 +8360,7 @@ command, and before the first command executes in a shell function (see
.SM
.B SHELL GRAMMAR
above).
Refer to the description of the \fBextglob\fP option to the
Refer to the description of the \fBextdebug\fP option to the
\fBshopt\fP builtin for details of its effect on the \fBDEBUG\fP trap.
If a
.I sigspec
@ -8487,8 +8615,7 @@ refers to a shell variable.
Read-only variables may not be unset.
If
.B \-f
is specifed,
each
is specified, each
.I name
refers to a shell function, and the function definition
is removed.
@ -8515,9 +8642,9 @@ subsequently reset. The exit status is true unless a
.I name
is readonly.
.TP
\fBwait\fP [\fIn\fP]
Wait for the specified process and return its termination
status.
\fBwait\fP [\fIn ...\fP]
Wait for each specified process and return its termination status.
Each
.I n
may be a process
ID or a job specification; if a job spec is given, all processes
@ -8661,7 +8788,7 @@ bfox@gnu.org
.PP
Chet Ramey, Case Western Reserve University
.br
chet@po.CWRU.Edu
chet@po.cwru.edu
.SH BUG REPORTS
If you find a bug in
.B bash,
@ -8702,7 +8829,7 @@ it provides for filing a bug report.
.PP
Comments and bug reports concerning
this manual page should be directed to
.IR chet@po.CWRU.Edu .
.IR chet@po.cwru.edu .
.SH BUGS
.PP
It's too big and too slow.

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-2004 Free Software Foundation, Inc.
Copyright @copyright{} 1988-2005 Free Software Foundation, Inc.
Permission is granted to make and distribute verbatim copies of
this manual provided the copyright notice and this permission notice
@ -94,46 +94,28 @@ reference on shell behavior.
@menu
* Introduction:: An introduction to the shell.
* Definitions:: Some definitions used in the rest of this
manual.
* Basic Shell Features:: The shell "building blocks".
* Shell Builtin Commands:: Commands that are a part of the shell.
* Shell Variables:: Variables used or set by Bash.
* Bash Features:: Features found only in Bash.
* Job Control:: A chapter describing what job control is
and how Bash allows you to use it.
* Using History Interactively:: Chapter dealing with history expansion
rules.
* Job Control:: What job control is and how Bash allows you
to use it.
* Using History Interactively:: Command History Expansion
* Command Line Editing:: Chapter describing the command line
editing features.
* Installing Bash:: How to build and install Bash on your system.
* Reporting Bugs:: How to report bugs in Bash.
* Major Differences From The Bourne Shell:: A terse list of the differences
between Bash and historical
versions of /bin/sh.
* Copying This Manual:: Copying this manual.
* Builtin Index:: Index of Bash builtin commands.
* Reserved Word Index:: Index of Bash reserved words.
* Variable Index:: Quick reference helps you find the
variable you want.
* Function Index:: Index of bindable Readline functions.
* Concept Index:: General index for concepts described in
this manual.
@end menu
@ -143,7 +125,6 @@ reference on shell behavior.
@chapter Introduction
@menu
* What is Bash?:: A short description of Bash.
* What is a shell?:: A brief introduction to shells.
@end menu
@ -371,9 +352,7 @@ and to named files, and how the shell executes commands.
@section Shell Syntax
@menu
* Shell Operation:: The basic operation of the shell.
* Quoting:: How to remove the special meaning from characters.
* Comments:: How to specify comments.
@end menu
@ -444,7 +423,6 @@ status (@pxref{Exit Status}).
* Double Quotes:: How to suppress most of the interpretation of a
sequence of characters.
* ANSI-C Quoting:: How to expand ANSI-C sequences in quoted strings.
* Locale Translation:: How to translate strings into different languages.
@end menu
@ -457,7 +435,8 @@ parameter expansion.
Each of the shell metacharacters (@pxref{Definitions})
has special meaning to the shell and must be quoted if it is to
represent itself.
When the command history expansion facilities are being used, the
When the command history expansion facilities are being used
(@pxref{History Interaction}), the
@var{history expansion} character, usually @samp{!}, must be quoted
to prevent history expansion. @xref{Bash History Facilities}, for
more details concerning history expansion.
@ -486,7 +465,8 @@ between single quotes, even when preceded by a backslash.
Enclosing characters in double quotes (@samp{"}) preserves the literal value
of all characters within the quotes, with the exception of
@samp{$}, @samp{`}, and @samp{\}.
@samp{$}, @samp{`}, @samp{\},
and, when history expansion is enabled, @samp{!}.
The characters @samp{$} and @samp{`}
retain their special meaning within double quotes (@pxref{Shell Expansions}).
The backslash retains its special meaning only when followed by one of
@ -497,8 +477,9 @@ characters are removed. Backslashes preceding characters without a
special meaning are left unmodified.
A double quote may be quoted within double quotes by preceding it with
a backslash.
When command history is being used, the double quote may not be used to
quote the history expansion character.
If enabled, history expansion will be performed unless an @samp{!}
appearing in double quotes is escaped using a backslash.
The backslash preceding the @samp{!} is not removed.
The special parameters @samp{*} and @samp{@@} have special meaning
when in double quotes (@pxref{Shell Parameter Expansion}).
@ -864,6 +845,10 @@ The syntax of the @code{case} command is:
@code{case} will selectively execute the @var{command-list} corresponding to
the first @var{pattern} that matches @var{word}.
If the shell option @code{nocasematch}
(see the description of @code{shopt} in @ref{Bash Builtins})
is enabled, the match is performed without regard to the case
of alphabetic characters.
The @samp{|} is used to separate multiple patterns, and the @samp{)}
operator terminates a pattern list.
A list of patterns and an associated command-list is known
@ -972,6 +957,10 @@ as primaries.
When the @samp{==} and @samp{!=} operators are used, the string to the
right of the operator is considered a pattern and matched according
to the rules described below in @ref{Pattern Matching}.
If the shell option @code{nocasematch}
(see the description of @code{shopt} in @ref{Bash Builtins})
is enabled, the match is performed without regard to the case
of alphabetic characters.
The return value is 0 if the string matches or does not match
the pattern, respectively, and 1 otherwise.
Any part of the pattern may be quoted to force it to be matched as a
@ -985,7 +974,7 @@ The return value is 0 if the string matches
the pattern, and 1 otherwise.
If the regular expression is syntactically incorrect, the conditional
expression's return value is 2.
If the shell option @code{nocaseglob}
If the shell option @code{nocasematch}
(see the description of @code{shopt} in @ref{Bash Builtins})
is enabled, the match is performed without regard to the case
of alphabetic characters.
@ -1118,12 +1107,12 @@ The first element of the @env{FUNCNAME} variable is set to the
name of the function while the function is executing.
All other aspects of the shell execution
environment are identical between a function and its caller
with the exception that the @env{DEBUG} trap
below) is not inherited unless the function has been given the
with the exception that the @env{DEBUG} and @env{RETURN} traps
are not inherited unless the function has been given the
@code{trace} attribute using the @code{declare} builtin or
the @code{-o functrace} option has been enabled with
the @code{set} builtin,
(in which case all functions inherit the @code{DEBUG} trap).
(in which case all functions inherit the @env{DEBUG} and @env{RETURN} traps).
@xref{Bourne Shell Builtins}, for the description of the
@code{trap} builtin.
@ -1208,6 +1197,21 @@ Assignment statements may also appear as arguments to the
@code{declare}, @code{typeset}, @code{export}, @code{readonly},
and @code{local} builtin commands.
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
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
(@pxref{Arrays}), the
variable's value is not unset (as it is when using @samp{=}), and new
values are appended to the array beginning at one greater than the array's
maximum index.
When applied to a string-valued variable, @var{value} is expanded and
appended to the variable's value.
@node Positional Parameters
@subsection Positional Parameters
@cindex parameters, positional
@ -1256,6 +1260,10 @@ Expands to the positional parameters, starting from one. When the
expansion occurs within double quotes, each parameter expands to a
separate word. That is, @code{"$@@"} is equivalent to
@code{"$1" "$2" @dots{}}.
If the double-quoted expansion occurs within a word, the expansion of
the first parameter is joined with the beginning part of the original
word, and the expansion of the last parameter is joined with the last
part of the original word.
When there are no positional parameters, @code{"$@@"} and
@code{$@@}
expand to nothing (i.e., they are removed).
@ -1292,12 +1300,13 @@ to the filename used to invoke Bash, as given by argument zero.
@item _
(An underscore.)
At shell startup, set to the absolute filename of the shell or shell
script being executed as passed in the argument list.
At shell startup, set to the absolute pathname used to invoke the
shell or shell script being executed as passed in the environment
or argument list.
Subsequently, expands to the last argument to the previous command,
after expansion.
Also set to the full pathname of each command executed and placed in
the environment exported to that command.
Also set to the full pathname used to invoke each command executed
and placed in the environment exported to that command.
When checking mail, this parameter holds the name of the mail file.
@end vtable
@ -1452,7 +1461,7 @@ If the login name is invalid, or the tilde expansion fails, the word is
left unchanged.
Each variable assignment is checked for unquoted tilde-prefixes immediately
following a @samp{:} or @samp{=}.
following a @samp{:} or the first @samp{=}.
In these cases, tilde expansion is also performed.
Consequently, one may use file names with tildes in assignments to
@env{PATH}, @env{MAILPATH}, and @env{CDPATH},
@ -1580,6 +1589,10 @@ parameters beginning at @var{offset}.
If @var{parameter} is an array name indexed by @samp{@@} or @samp{*},
the result is the @var{length}
members of the array beginning with @code{$@{@var{parameter}[@var{offset}]@}}.
A negative @var{offset} is taken relative to one greater than the maximum
index of the specified array.
Note that a negative offset must be separated from the colon by at least
one space to avoid being confused with the @samp{:-} expansion.
Substring indexing is zero-based unless the positional parameters
are used, in which case the indexing starts at 1.
@ -1927,7 +1940,7 @@ Matches zero or more occurrences of the given patterns.
Matches one or more occurrences of the given patterns.
@item @@(@var{pattern-list})
Matches exactly one of the given patterns.
Matches one of the given patterns.
@item !(@var{pattern-list})
Matches anything except one of the given patterns.
@ -2013,6 +2026,10 @@ connection to the corresponding socket.
A failure to open or create a file causes the redirection to fail.
Redirections using file descriptors greater than 9 should be used with
care, as they may conflict with file descriptors the shell uses
internally.
@subsection Redirecting Input
Redirection of input causes the file whose name results from
the expansion of @var{word}
@ -2188,21 +2205,15 @@ is not specified. If the file does not exist, it is created.
@menu
* Simple Command Expansion:: How Bash expands simple commands before
executing them.
* Command Search and Execution:: How Bash finds commands and runs them.
* Command Execution Environment:: The environment in which Bash
executes commands that are not
shell builtins.
* Environment:: The environment given to a command.
* Exit Status:: The status returned by commands and how Bash
interprets it.
* Signals:: What happens when Bash or a command it runs
receives a signal.
@end menu
@node Simple Command Expansion
@ -2603,6 +2614,8 @@ Many of the builtins have been extended by @sc{posix} or Bash.
Unless otherwise noted, each builtin command documented as accepting
options preceded by @samp{-} accepts @samp{--}
to signify the end of the options.
For example, the @code{:}, @code{true}, @code{false}, and @code{test}
builtins do not accept options.
@node Bourne Shell Builtins
@section Bourne Shell Builtins
@ -2893,6 +2906,8 @@ Evaluate a conditional expression @var{expr}.
Each operator and operand must be a separate argument.
Expressions are composed of the primaries described below in
@ref{Bash Conditional Expressions}.
@code{test} does not accept any options, nor does it accept and ignore
an argument of @option{--} as signifying the end of options.
When the @code{[} form is used, the last argument to the command must
be a @code{]}.
@ -3256,7 +3271,8 @@ by subsequent assignment statements or unset.
@item -t
Give each @var{name} the @code{trace} attribute.
Traced functions inherit the @code{DEBUG} trap from the calling shell.
Traced functions inherit the @code{DEBUG} and @code{RETURN} traps from
the calling shell.
The trace attribute has no special meaning for variables.
@item -x
@ -3295,6 +3311,8 @@ even on systems where they are interpreted by default.
The @code{xpg_echo} shell option may be used to
dynamically determine whether or not @code{echo} expands these
escape characters by default.
@code{echo} does not interpret @option{--} to mean the end of options.
@code{echo} interprets the following escape sequences:
@table @code
@item \a
@ -3409,7 +3427,7 @@ parent.
@item printf
@btindex printf
@example
@code{printf} @var{format} [@var{arguments}]
@code{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}.
@ -3427,6 +3445,9 @@ beginning with @samp{\0} may contain up to four digits),
and @samp{%q} causes @code{printf} to output the
corresponding @var{argument} in a format that can be reused as shell input.
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 reused as necessary to consume all of the @var{arguments}.
If the @var{format} requires more @var{arguments} than are supplied, the
extra format specifications behave as if a zero value or null string, as
@ -3610,6 +3631,20 @@ If the command run by the @code{DEBUG} trap returns a value of 2, and the
shell is executing in a subroutine (a shell function or a shell script
executed by the @code{.} or @code{source} builtins), a call to
@code{return} is simulated.
@item
@code{BASH_ARGC} and @code{BASH_ARGV} are updated as described in their
descriptions (@pxref{Bash Variables}).
@item
Function tracing is enabled: command substitution, shell functions, and
subshells invoked with @code{( @var{command} )} inherit the
@code{DEBUG} and @code{RETURN} traps.
@item
Error tracing is enabled: command substitution, shell functions, and
subshells invoked with @code{( @var{command} )} inherit the
@code{ERROR} trap.
@end enumerate
@item extglob
@ -3692,6 +3727,11 @@ on an empty line.
If set, Bash matches filenames in a case-insensitive fashion when
performing filename expansion.
@item nocasematch
If set, Bash matches patterns in a case-insensitive fashion when
performing matching while executing @code{case} or @code{[[}
conditional commands.
@item nullglob
If set, Bash allows filename patterns which match no
files to expand to a null string, rather than themselves.
@ -3885,7 +3925,10 @@ set [--abefhkmnptuvxBCHP] [-o @var{option}] [@var{argument} @dots{}]
If no options or arguments are supplied, @code{set} displays the names
and values of all shell variables and functions, sorted according to the
current locale, in a format that may be reused as input.
current locale, in a format that may be reused as input
for setting or resetting the currently-set variables.
Read-only variables cannot be reset.
In @sc{posix} mode, only shell variables are listed.
When options are supplied, they set or unset shell attributes.
Options, if specified, have the following meanings:
@ -4096,9 +4139,11 @@ $ cd ..; pwd
@end example
@item -T
If set, any trap on @code{DEBUG} is inherited by shell functions, command
substitutions, and commands executed in a subshell environment.
The @code{DEBUG} trap is normally not inherited in such cases.
If set, any trap on @code{DEBUG} and @code{RETURN} are inherited by
shell functions, command substitutions, and commands executed
in a subshell environment.
The @code{DEBUG} and @code{RETURN} traps are normally not inherited
in such cases.
@item --
If no arguments follow this option, then the positional parameters are
@ -4249,6 +4294,10 @@ parameters to the current subroutine (shell function or script executed
with @code{.} or @code{source}) is at the top of the stack. When a
subroutine is executed, the number of parameters passed is pushed onto
@code{BASH_ARGC}.
The shell sets @code{BASH_ARGC} only when in extended debugging mode
(see @ref{Bash Builtins}
for a description of the @code{extdebug} option to the @code{shopt}
builtin).
@item BASH_ARGV
An array variable containing all of the parameters in the current bash
@ -4256,6 +4305,10 @@ execution call stack. The final parameter of the last subroutine call
is at the top of the stack; the first parameter of the initial call is
at the bottom. When a subroutine is executed, the parameters supplied
are pushed onto @code{BASH_ARGV}.
The shell sets @code{BASH_ARGV} only when in extended debugging mode
(see @ref{Bash Builtins}
for a description of the @code{extdebug} option to the @code{shopt}
builtin).
@item BASH_COMMAND
The command currently being executed or about to be executed, unless the
@ -4274,8 +4327,8 @@ The command argument to the @option{-c} invocation option.
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
@code{$@{FUNCNAME[$i + 1]@}} was called.
The corresponding source file name is @code{$@{BASH_SOURCE[$i + 1]@}}.
@code{$@{FUNCNAME[$i]@}} was called.
The corresponding source file name is @code{$@{BASH_SOURCE[$i]@}}.
Use @code{LINENO} to obtain the current line number.
@item BASH_REMATCH
@ -4731,6 +4784,10 @@ prompt when the shell is interactive.
Bash terminates after that number of seconds if input does
not arrive.
@item TMPDIR
If set, Bash uses its value as the name of a directory in which
Bash creates temporary files for the shell's use.
@item UID
The numeric real user id of the current user. This variable is readonly.
@ -4783,7 +4840,7 @@ option).
@item --dump-po-strings
A list of all double-quoted strings preceded by @samp{$}
is printed on the standard ouput
is printed on the standard output
in the @sc{gnu} @code{gettext} PO (portable object) file format.
Equivalent to @option{-D} except for the output format.
@ -4870,7 +4927,7 @@ when invoking an interactive shell.
@item -D
A list of all double-quoted strings preceded by @samp{$}
is printed on the standard ouput.
is printed on the standard output.
These are the strings that
are subject to language translation when the current locale
is not @code{C} or @code{POSIX} (@pxref{Locale Translation}).
@ -5166,6 +5223,7 @@ shell to exit.
@item
When running in @sc{posix} mode, a special builtin returning an error
status will not cause the shell to exit (@pxref{Bash POSIX Mode}).
@item
A failed @code{exec} will not cause the shell to exit
(@pxref{Bourne Shell Builtins}).
@ -5201,6 +5259,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.
Unless otherwise specified, primaries that operate on files follow symbolic
links and operate on the target of the link, rather than the link itself.
@table @code
@item -a @var{file}
True if @var{file} exists.
@ -5414,7 +5475,7 @@ omitted, then base 10 is used.
The digits greater than 9 are represented by the lowercase letters,
the uppercase letters, @samp{@@}, and @samp{_}, in that order.
If @var{base} is less than or equal to 36, lowercase and uppercase
letters may be used interchangably to represent numbers between 10
letters may be used interchangeably to represent numbers between 10
and 35.
Operators are evaluated in order of precedence. Sub-expressions in
@ -5534,12 +5595,18 @@ The braces are required to avoid
conflicts with the shell's filename expansion operators. If the
@var{subscript} is @samp{@@} or @samp{*}, the word expands to all members
of the array @var{name}. These subscripts differ only when the word
appears within double quotes. If the word is double-quoted,
appears within double quotes.
If the word is double-quoted,
@code{$@{name[*]@}} expands to a single word with
the value of each array member separated by the first character of the
@env{IFS} variable, and @code{$@{name[@@]@}} expands each element of
@var{name} to a separate word. When there are no array members,
@code{$@{name[@@]@}} expands to nothing. This is analogous to the
@code{$@{name[@@]@}} expands to nothing.
If the double-quoted expansion occurs within a word, the expansion of
the first parameter is joined with the beginning part of the original
word, and the expansion of the last parameter is joined with the last
part of the original word.
This is analogous to the
expansion of the special parameters @samp{@@} and @samp{*}.
@code{$@{#name[}@var{subscript}@code{]@}} expands to the length of
@code{$@{name[}@var{subscript}@code{]@}}.
@ -5551,6 +5618,8 @@ referencing element zero.
The @code{unset} builtin is used to destroy arrays.
@code{unset} @var{name}[@var{subscript}]
destroys the array element at index @var{subscript}.
Care must be taken to avoid unwanted side effects caused by filename
generation.
@code{unset} @var{name}, where @var{name} is an array, removes the
entire array. A subscript of @samp{*} or @samp{@@} also removes the
entire array.
@ -5843,7 +5912,13 @@ is stopped is `Stopped(@var{signame})', where @var{signame} is, for
example, @code{SIGTSTP}.
@item
Reserved words may not be aliased.
The @code{bg} builtin uses the required format to describe each job placed
in the background, which does not include an indication of whether the job
is the current or previous job.
@item
Reserved words appearing in a context where reserved words are recognized
do not undergo alias expansion.
@item
The @sc{posix} 1003.2 @env{PS1} and @env{PS2} expansions of @samp{!} to
@ -5894,7 +5969,7 @@ may not start with a digit. Declaring a function with an invalid name
causes a fatal syntax error in non-interactive shells.
@item
@sc{posix} 1003.2 `special' builtins are found before shell functions
@sc{posix} 1003.2 special builtins are found before shell functions
during command lookup.
@item
@ -5904,12 +5979,6 @@ the POSIX.2 standard, and include things like passing incorrect options,
redirection errors, variable assignment errors for assignments preceding
the command name, and so on.
@item
If the @code{cd} builtin finds a directory to change to
using @env{$CDPATH}, the
value it assigns to the @env{PWD} variable does not contain any
symbolic links, as if @samp{cd -P} had been executed.
@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
@ -5989,29 +6058,61 @@ When the @code{cd} builtin is invoked in @var{logical} mode, and the pathname
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
@option{-P} option.
@item
When listing the history, the @code{fc} builtin does not include an
indication of whether or not a history entry has been modified.
@item
The default editor used by @code{fc} is @code{ed}.
@item
The @code{type} and @code{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 @code{$PATH}.
@item
The @code{vi} editing mode will invoke the @code{vi} editor directly when
the @samp{v} command is run, instead of checking @code{$FCEDIT} and
@code{$EDITOR}.
@item
When the @code{xpg_echo} option is enabled, Bash does not attempt to interpret
any arguments to @code{echo} as options. Each argument is displayed, after
escape characters are converted.
@end enumerate
There is other @sc{posix} 1003.2 behavior that Bash does not implement.
There is other @sc{posix} 1003.2 behavior that Bash does not implement by
default even when in @sc{posix} mode.
Specifically:
@enumerate
@item
Assignment statements affect the execution environment of all
builtins, not just special ones.
@item
When a subshell is created to execute a shell script with execute permission,
but without a leading @samp{#!}, Bash sets @code{$0} to the full pathname of
the script as found by searching @code{$PATH}, rather than the command as
typed by the user.
The @code{fc} builtin checks @code{$EDITOR} as a program to edit history
entries if @code{FCEDIT} is unset, rather than defaulting directly to
@code{ed}. @code{fc} uses @code{ed} if @code{EDITOR} is unset.
@item
When using @samp{.} to source a shell script found in @code{$PATH}, bash
checks execute permission bits rather than read permission bits, just as
if it were searching for a command.
As noted above, Bash requires the @code{xpg_echo} option to be enabled for
the @code{echo} builtin to be fully conformant.
@end enumerate
Bash can be configured to be @sc{posix}-conformant by default, by specifying
the @option{--enable-strict-posix-default} to @code{configure} when building
(@pxref{Optional Features}).
@node Job Control
@chapter Job Control
@ -6087,11 +6188,12 @@ There are a number of ways to refer to a job in the shell. The
character @samp{%} introduces a job name.
Job number @code{n} may be referred to as @samp{%n}.
The symbols @samp{%%} and
@samp{%+} refer to the shell's notion of the current job, which
is the last job stopped while it was in the foreground or started
in the background. The
previous job may be referenced using @samp{%-}. In output
The symbols @samp{%%} and @samp{%+} refer to the shell's notion of the
current job, which is the last job stopped while it was in the foreground
or started in the background.
A single @samp{%} (with no accompanying job specification) also refers
to the current job.
The previous job may be referenced using @samp{%-}. In output
pertaining to jobs (e.g., the output of the @code{jobs} command),
the current job is always flagged with a @samp{+}, and the
previous job with a @samp{-}.
@ -6132,15 +6234,15 @@ Bash does not print another warning, and the stopped jobs are terminated.
@item bg
@btindex bg
@example
bg [@var{jobspec}]
bg [@var{jobspec} @dots{}]
@end example
Resume the suspended job @var{jobspec} in the background, as if it
Resume each suspended job @var{jobspec} in the background, as if it
had been started with @samp{&}.
If @var{jobspec} is not supplied, the current job is used.
The return status is zero unless it is run when job control is not
enabled, or, when run with job control enabled, if @var{jobspec} was
not found or @var{jobspec} specifies a job that was started without
job control.
enabled, or, when run with job control enabled, any
@var{jobspec} was not found or specifies a job
that was started without job control.
@item fg
@btindex fg
@ -6216,11 +6318,11 @@ or non-zero if an error occurs or an invalid option is encountered.
@item wait
@btindex wait
@example
wait [@var{jobspec} or @var{pid}]
wait [@var{jobspec} or @var{pid} ...]
@end example
Wait until the child process specified by process @sc{id} @var{pid} or job
specification @var{jobspec} exits and return the exit status of the last
command waited for.
Wait until the child process specified by each process @sc{id} @var{pid}
or job specification @var{jobspec} exits and return the exit status of the
last command waited for.
If a job spec is given, all processes in the job are waited for.
If no arguments are given, all currently active child processes are
waited for, and the return status is zero.
@ -6304,23 +6406,16 @@ Other independent ports exist for
@menu
* Basic Installation:: Installation instructions.
* Compilers and Options:: How to set special options for various
systems.
* Compiling For Multiple Architectures:: How to compile Bash for more
than one kind of system from
the same source tree.
* Installation Names:: How to set the various paths used by the installation.
* Specifying the System Type:: How to configure Bash for a particular system.
* Sharing Defaults:: How to share default configuration values among GNU
programs.
* Operation Controls:: Options recognized by the configuration program.
* Optional Features:: How to enable and disable optional features when
building Bash.
@end menu
@ -6561,10 +6656,10 @@ Define if you are using the Andrew File System from Transarc.
@item --with-bash-malloc
Use the Bash version of
@code{malloc} in @file{lib/malloc/malloc.c}. This is not the same
@code{malloc} in the directory @file{lib/malloc}. This is not the same
@code{malloc} that appears in @sc{gnu} libc, but an older version
derived from the 4.2 @sc{bsd} @code{malloc}. This @code{malloc} is
very fast, but wastes some space on each allocation.
originally derived from the 4.2 @sc{bsd} @code{malloc}. This @code{malloc}
is very fast, but wastes some space on each allocation.
This option is enabled by default.
The @file{NOTES} file contains a list of systems for
which this should be turned off, and @code{configure} disables this
@ -6581,7 +6676,7 @@ A synonym for @code{--with-bash-malloc}.
@item --with-installed-readline[=@var{PREFIX}]
Define this to make Bash link with a locally-installed version of Readline
rather than the version in @file{lib/readline}. This works only with
Readline 4.3 and later versions. If @var{PREFIX} is @code{yes} or not
Readline 5.0 and later versions. If @var{PREFIX} is @code{yes} or not
supplied, @code{configure} uses the values of the make variables
@code{includedir} and @code{libdir}, which are subdirectories of @code{prefix}
by default, to find the installed version of Readline if it is not in
@ -6669,6 +6764,9 @@ Include support for matching POSIX regular expressions using the
@samp{=~} binary operator in the @code{[[} conditional command.
(@pxref{Conditional Constructs}).
@item --enable-debugger
Include support for the bash debugger (distributed separately).
@item --enable-directory-stack
Include support for a @code{csh}-like directory stack and the
@code{pushd}, @code{popd}, and @code{dirs} builtins
@ -6714,17 +6812,17 @@ when used in redirections (@pxref{Redirections}).
This enables process substitution (@pxref{Process Substitution}) if
the operating system provides the necessary support.
@item --enable-progcomp
Enable the programmable completion facilities
(@pxref{Programmable Completion}).
If Readline is not enabled, this option has no effect.
@item --enable-prompt-string-decoding
Turn on the interpretation of a number of backslash-escaped characters
in the @env{$PS1}, @env{$PS2}, @env{$PS3}, and @env{$PS4} prompt
strings. See @ref{Printing a Prompt}, for a complete list of prompt
string escape sequences.
@item --enable-progcomp
Enable the programmable completion facilities
(@pxref{Programmable Completion}).
If Readline is not enabled, this option has no effect.
@item --enable-readline
Include support for command-line editing and history with the Bash
version of the Readline library (@pxref{Command Line Editing}).
@ -6738,6 +6836,19 @@ when called as @code{rbash}, enters a restricted mode. See
Include the @code{select} builtin, 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
instead of storing the text internally.
@item --enable-single-help-strings
Store the text displayed by the @code{help} builtin as a single string for
each help topic. This aids in translating the text to different languages.
You may need to disable this if your compiler cannot handle very long string
literals.
@item --enable-strict-posix-default
Make Bash @sc{posix}-conformant by default (@pxref{Bash POSIX Mode}).
@item --enable-usg-echo-default
A synonym for @code{--enable-xpg-echo-default}.
@ -6746,7 +6857,7 @@ Make the @code{echo} builtin expand backslash-escaped characters by default,
without requiring the @option{-e} option.
This sets the default value of the @code{xpg_echo} shell option to @code{on},
which makes the Bash @code{echo} behave more like the version specified in
the Single Unix Specification, version 2.
the Single Unix Specification, version 3.
@xref{Bash Builtins}, for a description of the escape sequences that
@code{echo} recognizes.
@ -6810,8 +6921,8 @@ differences between the traditional Bourne shell and Bash; this
section quickly details the differences of significance. A
number of these differences are explained in greater depth in
previous sections.
This section uses the version of @code{sh} included in SVR4.2 as
the baseline reference.
This section uses the version of @code{sh} included in SVR4.2 (the
last version of the historical Bourne shell) as the baseline reference.
@itemize @bullet
@ -6863,6 +6974,8 @@ invocation options list the translatable strings found in a script
Bash implements the @code{!} keyword to negate the return value of
a pipeline (@pxref{Pipelines}).
Very useful when an @code{if} statement needs to act only if a test fails.
The Bash @samp{-o pipefail} option to @code{set} will cause a pipeline to
return a failure status if any command fails.
@item
Bash has the @code{time} reserved word and command timing (@pxref{Pipelines}).
@ -6879,7 +6992,12 @@ generation of simple menus (@pxref{Conditional Constructs}).
@item
Bash includes the @code{[[} compound command, which makes conditional
testing part of the shell grammar (@pxref{Conditional Constructs}).
testing part of the shell grammar (@pxref{Conditional Constructs}), including
optional regular expression matching.
@item
Bash provides optional case-insensitive matching for the @code{case} and
@code{[[} constructs.
@item
Bash includes brace expansion (@pxref{Brace Expansion}) and tilde
@ -6900,6 +7018,10 @@ exported to child processes. The Bourne shell does not normally do
this unless the variables are explicitly marked using the @code{export}
command.
@item
Bash supports the @samp{+=} assignment operator, which appends to the value
of the variable named on the left hand side.
@item
Bash includes the @sc{posix} pattern removal @samp{%}, @samp{#}, @samp{%%}
and @samp{##} expansions to remove leading or trailing substrings from
@ -6991,6 +7113,14 @@ opened for both reading and writing, and the @samp{&>} redirection
operator, for directing standard output and standard error to the same
file (@pxref{Redirections}).
@item
Bash includes the @samp{<<<} redirection operator, allowing a string to
be used as the standard input to a command.
@item
Bash implements the @samp{[n]<&@var{word}} and @samp{[n]>&@var{word}}
redirection operators, which move one file descriptor to another.
@item
Bash treats a number of filenames specially when they are
used in redirection operators (@pxref{Redirections}).
@ -7126,7 +7256,9 @@ The @code{trap} builtin (@pxref{Bourne Shell Builtins}) allows a
Commands specified with an @code{RETURN} trap are executed before
execution resumes after a shell function or a shell script executed with
@code{.} or @code{source} returns.
The @code{RETURN} trap is not inherited by shell functions.
The @code{RETURN} trap is not inherited by shell functions unless the
function has been given the @code{trace} attribute or the
@code{functrace} option has been enabled using the @code{shopt} builtin.
@item
The Bash @code{type} builtin is more extensive and gives more information
@ -7158,6 +7290,10 @@ job table (@pxref{Job Control Builtins}) or suppress the sending
of @code{SIGHUP} to a job when the shell exits as the result of a
@code{SIGHUP}.
@item
Bash includes a number of features to support a separate debugger for
shell scripts.
@item
The SVR4.2 shell has two privilege-related builtins
(@code{mldmode} and @code{priv}) not present in Bash.

1581
doc/rose94.ps Normal file

File diff suppressed because it is too large Load diff

View file

@ -1,10 +1,10 @@
@ignore
Copyright (C) 1988-2004 Free Software Foundation, Inc.
Copyright (C) 1988-2005 Free Software Foundation, Inc.
@end ignore
@set EDITION 3.0
@set VERSION 3.0
@set UPDATED 27 July 2004
@set UPDATED-MONTH July 2004
@set LASTCHANGE Mon Sep 5 11:47:04 EDT 2005
@set LASTCHANGE Tue Jul 27 09:12:07 EDT 2004
@set EDITION 3.1-beta1
@set VERSION 3.1-beta1
@set UPDATED 5 September 2005
@set UPDATED-MONTH September 2005

7
eval.c
View file

@ -63,8 +63,9 @@ int
reader_loop ()
{
int our_indirection_level;
COMMAND *current_command = (COMMAND *)NULL;
COMMAND * volatile current_command;
current_command = (COMMAND *)NULL;
USE_VAR(current_command);
our_indirection_level = ++indirection_level;
@ -146,13 +147,13 @@ reader_loop ()
execute_command (current_command);
exec_done:
QUIT;
if (current_command)
{
dispose_command (current_command);
current_command = (COMMAND *)NULL;
}
QUIT;
}
}
else

3
examples/bashdb/README Normal file
View file

@ -0,0 +1,3 @@
This is a sample implementation of a bash debugger. It is not the same
as the project available from http://bashdb.sourceforge.net, and has been
deprecated in favor of that implementation.

View file

@ -509,11 +509,11 @@ function _showline
fi
if (( $line < 100 )); then
_msg "$_guineapig:$line $bp $cl${_lines[$line]}"
_msg "${_guineapig/*\//}:$line $bp $cl${_lines[$line]}"
elif (( $line < 10 )); then
_msg "$_guineapig:$line $bp $cl${_lines[$line]}"
_msg "${_guineapig/*\//}:$line $bp $cl${_lines[$line]}"
elif (( $line > 0 )); then
_msg "$_guineapig:$line $bp $cl${_lines[$line]}"
_msg "${_guineapig/*\//}:$line $bp $cl${_lines[$line]}"
fi
}
@ -564,7 +564,7 @@ let _trace=0
let _i=1
# Be careful about quoted newlines
_potbelliedpig=${TMPDIR-/tmp}/$_guineapig.$$
_potbelliedpig=${TMPDIR-/tmp}/${_guineapig/*\//}.$$
sed 's,\\$,\\\\,' $_guineapig > $_potbelliedpig
_msg "Reading source from file: $_guineapig"

View file

@ -46,6 +46,17 @@ LOCAL_CFLAGS = @LOCAL_CFLAGS@
DEFS = @DEFS@
LOCAL_DEFS = @LOCAL_DEFS@
CPPFLAGS = @CPPFLAGS@
BASHINCDIR = ${topdir}/include
LIBBUILD = ${BUILD_DIR}/lib
INTL_LIBSRC = ${topdir}/lib/intl
INTL_BUILDDIR = ${LIBBUILD}/intl
INTL_INC = @INTL_INC@
LIBINTL_H = @LIBINTL_H@
CCFLAGS = $(DEFS) $(LOCAL_DEFS) $(LOCAL_CFLAGS) $(CFLAGS)
#
@ -63,8 +74,8 @@ SHOBJ_LIBS = @SHOBJ_LIBS@
SHOBJ_STATUS = @SHOBJ_STATUS@
INC = -I. -I.. -I$(topdir) -I$(topdir)/lib -I$(topdir)/builtins \
-I$(topdir)/include -I$(BUILD_DIR) -I$(BUILD_DIR)/lib \
-I$(BUILD_DIR)/builtins
-I$(BASHINCDIR) -I$(BUILD_DIR) -I$(LIBBUILD) \
-I$(BUILD_DIR)/builtins $(INTL_INC)
.c.o:
$(SHOBJ_CC) $(SHOBJ_CFLAGS) $(CCFLAGS) $(INC) -c -o $@ $<
@ -184,7 +195,7 @@ pushd.c: ${topdir}/builtins/pushd.def
pushd.o: pushd.c
$(RM) $@
$(SHOBJ_CC) -DPUSHD_AND_POPD -DLOADABLE_BUILTIN $(SHOBJ_CFLAGS) $(CFLAGS) $(INC) -c -o $@ $<
$(SHOBJ_CC) -DHAVE_CONFIG_H -DPUSHD_AND_POPD -DLOADABLE_BUILTIN $(SHOBJ_CFLAGS) $(CFLAGS) $(CPPFLAGS) $(INC) -c -o $@ $<
pushd: pushd.o
$(SHOBJ_LD) $(SHOBJ_LDFLAGS) $(SHOBJ_XLDFLAGS) -o $@ pushd.o $(SHOBJ_LIBS)

View file

@ -1039,7 +1039,7 @@ static const struct conf_variable conf_table[] =
#ifdef _PC_MAX_INPUT
{ "MAX_INPUT", PATHCONF, _PC_MAX_INPUT },
#endif
#ifdef _PC_NAMW_MAX
#ifdef _PC_NAME_MAX
{ "NAME_MAX", PATHCONF, _PC_NAME_MAX },
#endif
#ifdef _PC_PATH_MAX

View file

@ -22,7 +22,7 @@ mkalias ()
s/#/\#/g')
echo $1 \(\) "{" command "$comm" "; }"
;;
*) echo alias ${1}=\'$(echo "${2}" | sed "s:':'\\\\'':")\' ;;
*) echo alias ${1}=\'$(echo "${2}" | sed "s:':'\\\\'':g")\' ;;
esac
}
EOF

View file

@ -1,6 +1,6 @@
/* execute_command.c -- Execute a COMMAND structure. */
/* Copyright (C) 1987-2003 Free Software Foundation, Inc.
/* Copyright (C) 1987-2005 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@ -160,7 +160,7 @@ static int execute_while_command __P((WHILE_COM *));
static int execute_until_command __P((WHILE_COM *));
static int execute_while_or_until __P((WHILE_COM *, int));
static int execute_if_command __P((IF_COM *));
static int execute_null_command __P((REDIRECT *, int, int, int, pid_t));
static int execute_null_command __P((REDIRECT *, int, int, int));
static void fix_assignment_words __P((WORD_LIST *));
static int execute_simple_command __P((SIMPLE_COM *, int, int, int, struct fd_bitmap *));
static int execute_builtin __P((sh_builtin_func_t *, WORD_LIST *, int, int));
@ -245,6 +245,9 @@ int subshell_level = 0;
/* Currently-executing shell function. */
SHELL_VAR *this_shell_function;
/* If non-zero, matches in case and [[ ... ]] are case-insensitive */
int match_ignore_case = 0;
struct fd_bitmap *current_fds_to_close = (struct fd_bitmap *)NULL;
#define FD_BITMAP_DEFAULT_SIZE 32
@ -366,7 +369,6 @@ shell_control_structure (type)
{
switch (type)
{
case cm_for:
#if defined (ARITH_FOR_COMMAND)
case cm_arith_for:
#endif
@ -383,7 +385,9 @@ shell_control_structure (type)
case cm_while:
case cm_until:
case cm_if:
case cm_for:
case cm_group:
case cm_function_def:
return (1);
default:
@ -491,7 +495,7 @@ execute_command_internal (command, asynchronous, pipe_in, pipe_out,
{
int exec_result, invert, ignore_return, was_error_trap;
REDIRECT *my_undo_list, *exec_undo_list;
volatile pid_t last_pid;
volatile int last_pid;
volatile int save_line_number;
if (command == 0 || breaking || continuing || read_but_dont_execute)
@ -648,6 +652,9 @@ execute_command_internal (command, asynchronous, pipe_in, pipe_out,
/* We can't rely on variables retaining their values across a
call to execute_simple_command if a longjmp occurs as the
result of a `return' builtin. This is true for sure with gcc. */
#if defined (RECYCLES_PIDS)
last_made_pid = NO_PID;
#endif
last_pid = last_made_pid;
was_error_trap = signal_is_trapped (ERROR_TRAP) && signal_is_ignored (ERROR_TRAP) == 0;
@ -678,7 +685,7 @@ execute_command_internal (command, asynchronous, pipe_in, pipe_out,
/* XXX - this is something to watch out for if there are problems
when the shell is compiled without job control. */
if (already_making_children && pipe_out == NO_PIPE &&
last_pid != last_made_pid)
last_made_pid != last_pid)
{
stop_pipeline (asynchronous, (COMMAND *)NULL);
@ -698,14 +705,6 @@ execute_command_internal (command, asynchronous, pipe_in, pipe_out,
subshells forked to execute builtin commands (e.g., in
pipelines) to be waited for twice. */
exec_result = wait_for (last_made_pid);
#if defined (RECYCLES_PIDS)
/* LynxOS, for one, recycles pids very quickly -- so quickly
that a new process may have the same pid as the last one
created. This has been reported to fix the problem on that
OS, and a similar problem on Cygwin. */
if (exec_result == 0)
last_made_pid = NO_PID;
#endif
}
}
@ -1274,6 +1273,11 @@ execute_in_subshell (command, asynchronous, pipe_in, pipe_out, fds_to_close)
tcom = (command->type == cm_subshell) ? command->value.Subshell->command : command;
if (command->flags & CMD_TIME_PIPELINE)
tcom->flags |= CMD_TIME_PIPELINE;
if (command->flags & CMD_TIME_POSIX)
tcom->flags |= CMD_TIME_POSIX;
/* Make sure the subshell inherits any CMD_IGNORE_RETURN flag. */
if ((command->flags & CMD_IGNORE_RETURN) && tcom != command)
tcom->flags |= CMD_IGNORE_RETURN;
@ -1355,6 +1359,7 @@ execute_pipeline (command, asynchronous, pipe_in, pipe_out, fds_to_close)
#if defined (JOB_CONTROL)
terminate_current_pipeline ();
kill_current_pipeline ();
UNBLOCK_CHILD (oset);
#endif /* JOB_CONTROL */
last_command_exit_value = EXECUTION_FAILURE;
/* The unwind-protects installed below will take care
@ -1622,8 +1627,9 @@ execute_for_command (for_command)
if (echo_command_at_execute)
xtrace_print_for_command_head (for_command);
/* Save this command unless it's a trap command. */
if (this_command_name == 0 || (STREQ (this_command_name, "trap") == 0))
/* Save this command unless it's a trap command and we're not running
a debug trap. */
if (signal_in_progress (DEBUG_TRAP) == 0 && (this_command_name == 0 || (STREQ (this_command_name, "trap") == 0)))
{
FREE (the_printed_command_except_trap);
the_printed_command_except_trap = savestring (the_printed_command);
@ -1638,7 +1644,7 @@ execute_for_command (for_command)
#endif
this_command_name = (char *)NULL;
v = bind_variable (identifier, list->word->word);
v = bind_variable (identifier, list->word->word, 0);
if (readonly_p (v) || noassign_p (v))
{
line_number = save_line_number;
@ -1685,7 +1691,7 @@ execute_for_command (for_command)
{
SHELL_VAR *new_value;
new_value = bind_variable (identifier, value_cell(old_value));
new_value = bind_variable (identifier, value_cell(old_value), 0);
new_value->attributes = old_value->attributes;
dispose_variable (old_value);
}
@ -1731,8 +1737,11 @@ eval_arith_for_expr (l, okp)
command_string_index = 0;
print_arith_command (new);
FREE (the_printed_command_except_trap);
the_printed_command_except_trap = savestring (the_printed_command);
if (signal_in_progress (DEBUG_TRAP) == 0)
{
FREE (the_printed_command_except_trap);
the_printed_command_except_trap = savestring (the_printed_command);
}
r = run_debug_trap ();
/* In debugging mode, if the DEBUG trap returns a non-zero status, we
@ -2039,8 +2048,11 @@ execute_select_command (select_command)
if (echo_command_at_execute)
xtrace_print_select_command_head (select_command);
FREE (the_printed_command_except_trap);
the_printed_command_except_trap = savestring (the_printed_command);
if (signal_in_progress (DEBUG_TRAP) == 0 && (this_command_name == 0 || (STREQ (this_command_name, "trap") == 0)))
{
FREE (the_printed_command_except_trap);
the_printed_command_except_trap = savestring (the_printed_command);
}
retval = run_debug_trap ();
#if defined (DEBUGGER)
@ -2092,7 +2104,7 @@ execute_select_command (select_command)
break;
}
v = bind_variable (identifier, selection);
v = bind_variable (identifier, selection, 0);
if (readonly_p (v) || noassign_p (v))
{
if (readonly_p (v) && interactive_shell == 0 && posixly_correct)
@ -2168,7 +2180,7 @@ execute_case_command (case_command)
if (echo_command_at_execute)
xtrace_print_case_command_head (case_command);
if (this_command_name == 0 || (STREQ (this_command_name, "trap") == 0))
if (signal_in_progress (DEBUG_TRAP == 0) && (this_command_name == 0 || (STREQ (this_command_name, "trap") == 0)))
{
FREE (the_printed_command_except_trap);
the_printed_command_except_trap = savestring (the_printed_command);
@ -2185,14 +2197,6 @@ execute_case_command (case_command)
}
#endif
/* Posix.2 specifies that the WORD is tilde expanded. */
if (member ('~', case_command->word->word))
{
word = bash_tilde_expand (case_command->word->word, 0);
free (case_command->word->word);
case_command->word->word = word;
}
wlist = expand_word_unsplit (case_command->word, 0);
word = wlist ? string_list (wlist) : savestring ("");
dispose_words (wlist);
@ -2210,15 +2214,6 @@ execute_case_command (case_command)
QUIT;
for (list = clauses->patterns; list; list = list->next)
{
/* Posix.2 specifies to tilde expand each member of the pattern
list. */
if (member ('~', list->word->word))
{
pattern = bash_tilde_expand (list->word->word, 0);
free (list->word->word);
list->word->word = pattern;
}
es = expand_word_leave_quoted (list->word, 0);
if (es && es->word && es->word->word && *(es->word->word))
@ -2232,7 +2227,7 @@ execute_case_command (case_command)
/* Since the pattern does not undergo quote removal (as per
Posix.2, section 3.9.4.3), the strmatch () call must be able
to recognize backslashes as escape characters. */
match = strmatch (pattern, word, FNMATCH_EXTFLAG) != FNM_NOMATCH;
match = strmatch (pattern, word, FNMATCH_EXTFLAG|FNMATCH_IGNCASE) != FNM_NOMATCH;
free (pattern);
dispose_words (es);
@ -2395,8 +2390,12 @@ execute_arith_command (arith_command)
command_string_index = 0;
print_arith_command (arith_command->exp);
FREE (the_printed_command_except_trap);
the_printed_command_except_trap = savestring (the_printed_command);
if (signal_in_progress (DEBUG_TRAP) == 0)
{
FREE (the_printed_command_except_trap);
the_printed_command_except_trap = savestring (the_printed_command);
}
/* Run the debug trap before each arithmetic command, but do it after we
update the line number information and before we expand the various
@ -2508,9 +2507,15 @@ execute_cond_node (cond)
}
else
#endif /* COND_REGEXP */
result = binary_test (cond->op->word, arg1, arg2, TEST_PATMATCH|TEST_ARITHEXP)
? EXECUTION_SUCCESS
: EXECUTION_FAILURE;
{
int oe;
oe = extended_glob;
extended_glob = 1;
result = binary_test (cond->op->word, arg1, arg2, TEST_PATMATCH|TEST_ARITHEXP)
? EXECUTION_SUCCESS
: EXECUTION_FAILURE;
extended_glob = oe;
}
if (arg1 != nullstr)
free (arg1);
if (arg2 != nullstr)
@ -2546,8 +2551,12 @@ execute_cond_command (cond_command)
command_string_index = 0;
print_cond_command (cond_command);
FREE (the_printed_command_except_trap);
the_printed_command_except_trap = savestring (the_printed_command);
if (signal_in_progress (DEBUG_TRAP) == 0)
{
FREE (the_printed_command_except_trap);
the_printed_command_except_trap = savestring (the_printed_command);
}
/* Run the debug trap before each conditional command, but do it after we
update the line number information. */
@ -2580,7 +2589,7 @@ bind_lastarg (arg)
if (arg == 0)
arg = "";
var = bind_variable ("_", arg);
var = bind_variable ("_", arg, 0);
VUNSETATTR (var, att_exported);
}
@ -2588,10 +2597,9 @@ bind_lastarg (arg)
to be run asynchronously. This handles all the side effects that are
supposed to take place. */
static int
execute_null_command (redirects, pipe_in, pipe_out, async, old_last_command_subst_pid)
execute_null_command (redirects, pipe_in, pipe_out, async)
REDIRECT *redirects;
int pipe_in, pipe_out, async;
pid_t old_last_command_subst_pid;
{
int r;
@ -2637,7 +2645,7 @@ execute_null_command (redirects, pipe_in, pipe_out, async, old_last_command_subs
if (r != 0)
return (EXECUTION_FAILURE);
else if (old_last_command_subst_pid != last_command_subst_pid)
else if (last_command_subst_pid != NO_PID)
return (last_command_exit_value);
else
return (EXECUTION_SUCCESS);
@ -2666,8 +2674,10 @@ fix_assignment_words (words)
b = builtin_address_internal (words->word->word, 0);
if (b == 0 || (b->flags & ASSIGNMENT_BUILTIN) == 0)
return;
else if (b && (b->flags & ASSIGNMENT_BUILTIN))
words->word->flags |= W_ASSNBLTIN;
}
w->word->flags |= (W_NOSPLIT|W_NOGLOB|W_TILDEEXP);
w->word->flags |= (W_NOSPLIT|W_NOGLOB|W_TILDEEXP|W_ASSIGNARG);
}
}
@ -2683,7 +2693,7 @@ execute_simple_command (simple_command, pipe_in, pipe_out, async, fds_to_close)
WORD_LIST *words, *lastword;
char *command_line, *lastarg, *temp;
int first_word_quoted, result, builtin_is_special, already_forked, dofork;
pid_t old_last_command_subst_pid, old_last_async_pid;
pid_t old_last_async_pid;
sh_builtin_func_t *builtin;
SHELL_VAR *func;
@ -2699,10 +2709,10 @@ execute_simple_command (simple_command, pipe_in, pipe_out, async, fds_to_close)
command_string_index = 0;
print_simple_command (simple_command);
if (this_command_name == 0 || (STREQ (this_command_name, "trap") == 0))
if (signal_in_progress (DEBUG_TRAP) == 0 && (this_command_name == 0 || (STREQ (this_command_name, "trap") == 0)))
{
FREE (the_printed_command_except_trap);
the_printed_command_except_trap = savestring (the_printed_command);
the_printed_command_except_trap = the_printed_command ? savestring (the_printed_command) : (char *)0;
}
/* Run the debug trap before each simple command, but do it after we
@ -2718,7 +2728,7 @@ execute_simple_command (simple_command, pipe_in, pipe_out, async, fds_to_close)
first_word_quoted =
simple_command->words ? (simple_command->words->word->flags & W_QUOTED): 0;
old_last_command_subst_pid = last_command_subst_pid;
last_command_subst_pid = NO_PID;
old_last_async_pid = last_asynchronous_pid;
already_forked = dofork = 0;
@ -2739,27 +2749,22 @@ execute_simple_command (simple_command, pipe_in, pipe_out, async, fds_to_close)
if (dofork)
{
#if 0
/* XXX memory leak if expand_words() error causes a jump_to_top_level */
command_line = savestring (the_printed_command);
#endif
/* Do this now, because execute_disk_command will do it anyway in the
vast majority of cases. */
maybe_make_export_env ();
#if 0
if (make_child (command_line, async) == 0)
#else
if (make_child (savestring (the_printed_command), async) == 0)
#endif
/* Don't let a DEBUG trap overwrite the command string to be saved with
the process/job associated with this child. */
if (make_child (savestring (the_printed_command_except_trap), async) == 0)
{
already_forked = 1;
simple_command->flags |= CMD_NO_FORK;
subshell_environment = (pipe_in != NO_PIPE || pipe_out != NO_PIPE)
? (SUBSHELL_PIPE|SUBSHELL_FORK)
: (SUBSHELL_ASYNC|SUBSHELL_FORK);
subshell_environment = SUBSHELL_FORK;
if (pipe_in != NO_PIPE || pipe_out != NO_PIPE)
subshell_environment |= SUBSHELL_PIPE;
if (async)
subshell_environment |= SUBSHELL_ASYNC;
/* We need to do this before piping to handle some really
pathological cases where one of the pipe file descriptors
@ -2804,8 +2809,7 @@ execute_simple_command (simple_command, pipe_in, pipe_out, async, fds_to_close)
this_command_name = 0;
result = execute_null_command (simple_command->redirects,
pipe_in, pipe_out,
already_forked ? 0 : async,
old_last_command_subst_pid);
already_forked ? 0 : async);
if (already_forked)
exit (result);
else
@ -3048,8 +3052,10 @@ execute_builtin (builtin, words, flags, subshell)
/* The temporary environment for a builtin is supposed to apply to
all commands executed by that builtin. Currently, this is a
problem only with the `source' and `eval' builtins. */
isbltinenv = (builtin == source_builtin || builtin == eval_builtin);
problem only with the `unset', `source' and `eval' builtins. */
isbltinenv = (builtin == source_builtin || builtin == eval_builtin || builtin == unset_builtin);
if (isbltinenv)
{
if (subshell == 0)
@ -3059,7 +3065,7 @@ execute_builtin (builtin, words, flags, subshell)
{
push_scope (VC_BLTNENV, temporary_env);
if (subshell == 0)
add_unwind_protect (pop_scope, "1");
add_unwind_protect (pop_scope, (flags & CMD_COMMAND_BUILTIN) ? 0 : "1");
temporary_env = (HASH_TABLE *)NULL;
}
}
@ -3105,7 +3111,7 @@ execute_function (var, words, flags, fds_to_close, async, subshell)
COMMAND *tc, *fc, *save_current;
char *debug_trap, *error_trap, *return_trap;
#if defined (ARRAY_VARS)
SHELL_VAR *funcname_v, *bash_source_v, *bash_lineno_v;
SHELL_VAR *funcname_v, *nfv, *bash_source_v, *bash_lineno_v;
ARRAY *funcname_a, *bash_source_a, *bash_lineno_a;
#endif
FUNCTION_DEF *shell_fn;
@ -3178,7 +3184,13 @@ execute_function (var, words, flags, fds_to_close, async, subshell)
restore_default_signal (ERROR_TRAP);
}
/* Shell functions inherit the RETURN trap if function tracing is on
globally or on individually for this function. */
#if 0
if (return_trap && ((trace_p (var) == 0) && function_trace_mode == 0))
#else
if (return_trap && (signal_in_progress (DEBUG_TRAP) || ((trace_p (var) == 0) && function_trace_mode == 0)))
#endif
{
if (subshell == 0)
{
@ -3214,24 +3226,24 @@ execute_function (var, words, flags, fds_to_close, async, subshell)
/* Number of the line on which the function body starts. */
line_number = function_line_number = tc->line;
if (subshell)
{
#if defined (JOB_CONTROL)
stop_pipeline (async, (COMMAND *)NULL);
if (subshell)
stop_pipeline (async, (COMMAND *)NULL);
#endif
fc = (tc->type == cm_group) ? tc->value.Group->command : tc;
if (fc && (flags & CMD_IGNORE_RETURN))
fc->flags |= CMD_IGNORE_RETURN;
}
else
fc = tc;
fc = tc;
return_catch_flag++;
return_val = setjmp (return_catch);
if (return_val)
result = return_catch_value;
{
result = return_catch_value;
/* Run the RETURN trap in the function's context. */
save_current = currently_executing_command;
run_return_trap ();
currently_executing_command = save_current;
}
else
{
/* Run the debug trap here so we can trap at the start of a function's
@ -3255,6 +3267,10 @@ execute_function (var, words, flags, fds_to_close, async, subshell)
}
#else
result = execute_command_internal (fc, 0, NO_PIPE, NO_PIPE, fds_to_close);
save_current = currently_executing_command;
run_return_trap ();
currently_executing_command = save_current;
#endif
showing_function_line = 0;
}
@ -3268,9 +3284,16 @@ execute_function (var, words, flags, fds_to_close, async, subshell)
funcnest--;
#if defined (ARRAY_VARS)
/* These two variables cannot be unset, and cannot be affected by the
function. */
array_pop (bash_source_a);
array_pop (funcname_a);
array_pop (bash_lineno_a);
/* FUNCNAME can be unset, and so can potentially be changed by the
function. */
GET_ARRAY_FROM_VAR ("FUNCNAME", nfv, funcname_a);
if (nfv == funcname_v)
array_pop (funcname_a);
#endif
if (variable_context == 0 || this_shell_function == 0)
@ -3759,6 +3782,7 @@ initialize_subshell ()
/* Forget about the way job control was working. We are in a subshell. */
without_job_control ();
set_sigchld_handler ();
init_job_stats ();
#endif /* JOB_CONTROL */
/* Reset the values of the shell flags and options. */
@ -3833,6 +3857,12 @@ shell_execve (command, args, env)
errno = i;
file_error (command);
}
/* errors not involving the path argument to execve. */
else if (i == E2BIG || i == ENOMEM)
{
errno = i;
file_error (command);
}
else
{
/* The file has the execute bits set, but the kernel refuses to
@ -3842,9 +3872,18 @@ shell_execve (command, args, env)
if (sample_len > 2 && sample[0] == '#' && sample[1] == '!')
{
char *interp;
int ilen;
interp = getinterp (sample, sample_len, (int *)NULL);
ilen = strlen (interp);
errno = i;
if (interp[ilen - 1] == '\r')
{
interp = xrealloc (interp, ilen + 2);
interp[ilen - 1] = '^';
interp[ilen] = 'M';
interp[ilen + 1] = '\0';
}
sys_error (_("%s: %s: bad interpreter"), command, interp ? interp : "");
FREE (interp);
return (EX_NOEXEC);

5
expr.c
View file

@ -769,7 +769,7 @@ exppower ()
while (curtok == POWER)
{
readtok ();
val2 = exp1 ();
val2 = exppower (); /* exponentiation is right-associative */
if (val2 == 0)
return (1);
if (val2 < 0)
@ -1135,7 +1135,7 @@ evalerror (msg)
Base may be >=2 and <=64. If base is <= 36, the numbers are drawn
from [0-9][a-zA-Z], and lowercase and uppercase letters may be used
interchangably. If base is > 36 and <= 64, the numbers are drawn
from [0-9][a-z][A-Z]_@ (a = 10, z = 35, A = 36, Z = 61, _ = 62, @ = 63 --
from [0-9][a-z][A-Z]_@ (a = 10, z = 35, A = 36, Z = 61, @ = 62, _ = 63 --
you get the picture). */
static intmax_t
@ -1206,6 +1206,7 @@ strlong (num)
else
break;
}
return (val);
}

View file

@ -1,7 +1,7 @@
/* externs.h -- extern function declarations which do not appear in their
own header file. */
/* Copyright (C) 1993-2002 Free Software Foundation, Inc.
/* Copyright (C) 1993-2005 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@ -235,6 +235,7 @@ extern int sh_regmatch __P((const char *, const char *, int));
/* 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_mkdoublequoted __P((const char *, int, int));
extern char *sh_un_double_quote __P((char *));
extern char *sh_backslash_quote __P((char *));
extern char *sh_backslash_quote_for_double_quotes __P((char *));
@ -302,6 +303,16 @@ extern void strvec_sort __P((char **));
extern char **strvec_from_word_list __P((WORD_LIST *, int, int, int *));
extern WORD_LIST *strvec_to_word_list __P((char **, int, int));
/* declarations for functions defined in lib/sh/strnlen.c */
#if !defined (HAVE_STRNLEN)
extern size_t strnlen __P((const char *, size_t));
#endif
/* declarations for functions defined in lib/sh/strpbrk.c */
#if !defined (HAVE_STRPBRK)
extern char *strpbrk __P((const char *, const char *));
#endif
/* declarations for functions defined in lib/sh/strtod.c */
#if !defined (HAVE_STRTOD)
extern double strtod __P((const char *, char **));
@ -358,10 +369,16 @@ extern char *sh_mktmpname __P((char *, int));
extern int sh_mktmpfd __P((char *, int, char **));
/* extern FILE *sh_mktmpfp __P((char *, int, char **)); */
/* declarations for functions defined in lib/sh/winsize.c */
extern void get_new_window_size __P((int, int *, int *));
/* declarations for functions defined in lib/sh/xstrchr.c */
#undef xstrchr
extern char *xstrchr __P((const char *, int));
/* declarations for functions defined in lib/sh/zcatfd.c */
extern int zcatfd __P((int, int, char *));
/* declarations for functions defined in lib/sh/zread.c */
extern ssize_t zread __P((int, char *, size_t));
extern ssize_t zreadintr __P((int, char *, size_t));

View file

@ -72,11 +72,6 @@ int check_hashed_filenames;
containing the file of interest. */
int dot_found_in_search = 0;
#define u_mode_bits(x) (((x) & 0000700) >> 6)
#define g_mode_bits(x) (((x) & 0000070) >> 3)
#define o_mode_bits(x) (((x) & 0000007) >> 0)
#define X_BIT(x) ((x) & 1)
/* Return some flags based on information about this file.
The EXISTS bit is non-zero if the file is found.
The EXECABLE bit is non-zero the file is executble.
@ -86,6 +81,7 @@ file_status (name)
const char *name;
{
struct stat finfo;
int r;
/* Determine whether this file exists or not. */
if (stat (name, &finfo) < 0)
@ -96,41 +92,62 @@ file_status (name)
if (S_ISDIR (finfo.st_mode))
return (FS_EXISTS|FS_DIRECTORY);
r = FS_EXISTS;
#if defined (AFS)
/* We have to use access(2) to determine access because AFS does not
support Unix file system semantics. This may produce wrong
answers for non-AFS files when ruid != euid. I hate AFS. */
return ((access (name, X_OK) == 0) ? (FS_EXISTS|FS_EXECABLE) : FS_EXISTS);
if (access (name, X_OK) == 0)
r |= FS_EXECABLE;
if (access (name, R_OK) == 0)
r |= FS_READABLE;
return r;
#else /* !AFS */
/* Find out if the file is actually executable. By definition, the
only other criteria is that the file has an execute bit set that
we can use. */
we can use. The same with whether or not a file is readable. */
/* Root only requires execute permission for any of owner, group or
others to be able to exec a file. */
others to be able to exec a file, and can read any file. */
if (current_user.euid == (uid_t)0)
{
int bits;
bits = (u_mode_bits (finfo.st_mode) |
g_mode_bits (finfo.st_mode) |
o_mode_bits (finfo.st_mode));
return ((X_BIT (bits)) ? (FS_EXISTS | FS_EXECABLE) : FS_EXISTS);
r |= FS_READABLE;
if (finfo.st_mode & S_IXUGO)
r |= FS_EXECABLE;
return r;
}
/* If we are the owner of the file, the owner execute bit applies. */
/* If we are the owner of the file, the owner bits apply. */
if (current_user.euid == finfo.st_uid)
return ((X_BIT (u_mode_bits (finfo.st_mode))) ? (FS_EXISTS | FS_EXECABLE) : FS_EXISTS);
{
if (finfo.st_mode & S_IXUSR)
r |= FS_EXECABLE;
if (finfo.st_mode & S_IRUSR)
r |= FS_READABLE;
}
/* If we are in the owning group, the group permissions apply. */
else if (group_member (finfo.st_gid))
return ((X_BIT (g_mode_bits (finfo.st_mode))) ? (FS_EXISTS | FS_EXECABLE) : FS_EXISTS);
{
if (finfo.st_mode & S_IXGRP)
r |= FS_EXECABLE;
if (finfo.st_mode & S_IRGRP)
r |= FS_READABLE;
}
/* Else we check whether `others' have permission to execute the file */
else
return ((X_BIT (o_mode_bits (finfo.st_mode))) ? (FS_EXISTS | FS_EXECABLE) : FS_EXISTS);
{
if (finfo.st_mode & S_IXOTH)
r |= FS_EXECABLE;
if (finfo.st_mode & S_IROTH)
r |= FS_READABLE;
}
return r;
#endif /* !AFS */
}
@ -180,12 +197,13 @@ find_user_command (name)
/* Locate the file referenced by NAME, searching along the contents
of the shell PATH variable. Return a new string which is the full
pathname to the file, or NULL if the file couldn't be found. This
returns the first file found. */
returns the first readable file found; designed to be used to look
for shell scripts or files to source. */
char *
find_path_file (name)
const char *name;
{
return (find_user_command_internal (name, FS_EXISTS));
return (find_user_command_internal (name, FS_READABLE));
}
static char *
@ -460,9 +478,14 @@ find_in_path_element (name, path, flags, name_len, dotinfop)
if (flags & FS_EXISTS)
return (full_path);
/* If we have a readable file, and the caller wants a readable file, this
is it. */
if ((flags & FS_READABLE) && (status & FS_READABLE))
return (full_path);
/* If the file is executable, then it satisfies the cases of
EXEC_ONLY and EXEC_PREFERRED. Return this file unconditionally. */
if ((status & FS_EXECABLE) &&
if ((status & FS_EXECABLE) && (flags & (FS_EXEC_ONLY|FS_EXEC_PREFERRED)) &&
(((flags & FS_NODIRS) == 0) || ((status & FS_DIRECTORY) == 0)))
{
FREE (file_to_lose_on);
@ -477,9 +500,11 @@ find_in_path_element (name, path, flags, name_len, dotinfop)
file_to_lose_on = savestring (full_path);
/* If we want only executable files, or we don't want directories and
this file is a directory, fail. */
if ((flags & FS_EXEC_ONLY) || (flags & FS_EXEC_PREFERRED) ||
((flags & FS_NODIRS) && (status & FS_DIRECTORY)))
this file is a directory, or we want a readable file and this file
isn't readable, fail. */
if ((flags & (FS_EXEC_ONLY|FS_EXEC_PREFERRED)) ||
((flags & FS_NODIRS) && (status & FS_DIRECTORY)) ||
((flags & FS_READABLE) && (status & FS_READABLE) == 0))
{
free (full_path);
return ((char *)NULL);

135
general.c
View file

@ -39,6 +39,8 @@
#include "bashintl.h"
#include "shell.h"
#include "test.h"
#include <tilde/tilde.h>
#if !defined (errno)
@ -286,10 +288,16 @@ assignment (string, flags)
newi = skipsubscript (string, indx);
if (string[newi++] != ']')
return (0);
if (string[newi] == '+' && string[newi+1] == '=')
return (newi + 1);
return ((string[newi] == '=') ? newi : 0);
}
#endif /* ARRAY_VARS */
/* Check for `+=' */
if (c == '+' && string[indx+1] == '=')
return (indx + 1);
/* Variable names in assignment statements may contain only letters,
digits, and `_'. */
if (legal_variable_char (c) == 0)
@ -498,6 +506,36 @@ file_iswdir (fn)
return (file_isdir (fn) && test_eaccess (fn, W_OK) == 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
absolute_pathname (string)
const char *string;
{
if (string == 0 || *string == '\0')
return (0);
if (ABSPATH(string))
return (1);
if (string[0] == '.' && PATHSEP(string[1])) /* . and ./ */
return (1);
if (string[0] == '.' && string[1] == '.' && PATHSEP(string[2])) /* .. and ../ */
return (1);
return (0);
}
/* Return 1 if STRING is an absolute program name; it is absolute if it
contains any slashes. This is used to decide whether or not to look
up through $PATH. */
int
absolute_program (string)
const char *string;
{
return ((char *)xstrchr (string, '/') != (char *)NULL);
}
/* **************************************************************** */
/* */
@ -532,47 +570,21 @@ make_absolute (string, dot_path)
return (result);
}
/* 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
absolute_pathname (string)
const char *string;
{
if (string == 0 || *string == '\0')
return (0);
if (ABSPATH(string))
return (1);
if (string[0] == '.' && PATHSEP(string[1])) /* . and ./ */
return (1);
if (string[0] == '.' && string[1] == '.' && PATHSEP(string[2])) /* .. and ../ */
return (1);
return (0);
}
/* Return 1 if STRING is an absolute program name; it is absolute if it
contains any slashes. This is used to decide whether or not to look
up through $PATH. */
int
absolute_program (string)
const char *string;
{
return ((char *)xstrchr (string, '/') != (char *)NULL);
}
/* Return the `basename' of the pathname in STRING (the stuff after the
last '/'). If STRING is not a full pathname, simply return it. */
last '/'). If STRING is `/', just return it. */
char *
base_pathname (string)
char *string;
{
char *p;
#if 0
if (absolute_pathname (string) == 0)
return (string);
#endif
if (string[0] == '/' && string[1] == 0)
return (string);
p = (char *)strrchr (string, '/');
return (p ? ++p : string);
@ -683,7 +695,9 @@ extern char *get_dirstack_from_string __P((char *));
#endif
static char **bash_tilde_prefixes;
static char **bash_tilde_prefixes2;
static char **bash_tilde_suffixes;
static char **bash_tilde_suffixes2;
/* If tilde_expand hasn't been able to expand the text, perhaps it
is a special shell expansion. This function is installed as the
@ -731,6 +745,10 @@ tilde_initialize ()
bash_tilde_prefixes[1] = ":~";
bash_tilde_prefixes[2] = (char *)NULL;
bash_tilde_prefixes2 = strvec_create (2);
bash_tilde_prefixes2[0] = ":~";
bash_tilde_prefixes2[1] = (char *)NULL;
tilde_additional_prefixes = bash_tilde_prefixes;
bash_tilde_suffixes = strvec_create (3);
@ -739,6 +757,10 @@ tilde_initialize ()
bash_tilde_suffixes[2] = (char *)NULL;
tilde_additional_suffixes = bash_tilde_suffixes;
bash_tilde_suffixes2 = strvec_create (2);
bash_tilde_suffixes2[0] = ":";
bash_tilde_suffixes2[1] = (char *)NULL;
}
}
@ -770,9 +792,49 @@ unquoted_tilde_word (s)
return 1;
}
/* Find the end of the tilde-prefix starting at S, and return the tilde
prefix in newly-allocated memory. Return the length of the string in
*LENP. FLAGS tells whether or not we're in an assignment context --
if so, `:' delimits the end of the tilde prefix as well. */
char *
bash_tilde_find_word (s, flags, lenp)
const char *s;
int flags, *lenp;
{
const char *r;
char *ret;
int l;
for (r = s; *r && *r != '/'; r++)
{
/* Short-circuit immediately if we see a quote character. Even though
POSIX says that `the first unquoted slash' (or `:') terminates the
tilde-prefix, in practice, any quoted portion of the tilde prefix
will cause it to not be expanded. */
if (*r == '\\' || *r == '\'' || *r == '"')
{
ret = savestring (s);
if (lenp)
*lenp = 0;
return ret;
}
else if (flags && *r == ':')
break;
}
l = r - s;
ret = xmalloc (l + 1);
strncpy (ret, s, l);
ret[l] = '\0';
if (lenp)
*lenp = l;
return ret;
}
/* Tilde-expand S by running it through the tilde expansion library.
ASSIGN_P is 1 if this is a variable assignment, so the alternate
tilde prefixes should be enabled (`=~' and `:~', see above). */
tilde prefixes should be enabled (`=~' and `:~', see above). If
ASSIGN_P is 2, we are expanding the rhs of an assignment statement,
so `=~' is not valid. */
char *
bash_tilde_expand (s, assign_p)
const char *s;
@ -783,7 +845,12 @@ bash_tilde_expand (s, assign_p)
old_immed = interrupt_immediately;
interrupt_immediately = 1;
tilde_additional_prefixes = assign_p ? bash_tilde_prefixes : (char **)0;
tilde_additional_prefixes = assign_p == 0 ? (char **)0
: (assign_p == 2 ? bash_tilde_prefixes2 : bash_tilde_prefixes);
if (assign_p == 2)
tilde_additional_suffixes = bash_tilde_suffixes2;
r = (*s == '~') ? unquoted_tilde_word (s) : 1;
ret = r ? tilde_expand (s) : savestring (s);
interrupt_immediately = old_immed;

View file

@ -24,6 +24,7 @@
#include "stdc.h"
#include "bashtypes.h"
#include "chartypes.h"
#if defined (HAVE_SYS_RESOURCE_H) && defined (RLIMTYPE)
# if defined (HAVE_SYS_TIME_H)
@ -129,16 +130,16 @@ typedef struct {
: (type)(list))
#if __GNUC__ > 1
# define FASTCOPY(s, d, n) __builtin_memcpy (d, s, n)
# define FASTCOPY(s, d, n) __builtin_memcpy ((d), (s), (n))
#else /* !__GNUC__ */
# if !defined (HAVE_BCOPY)
# if !defined (HAVE_MEMMOVE)
# define FASTCOPY(s, d, n) memcpy (d, s, n)
# define FASTCOPY(s, d, n) memcpy ((d), (s), (n))
# else
# define FASTCOPY(s, d, n) memmove (d, s, n)
# define FASTCOPY(s, d, n) memmove ((d), (s), (n))
# endif /* !HAVE_MEMMOVE */
# else /* HAVE_BCOPY */
# define FASTCOPY(s, d, n) bcopy (s, d, n)
# define FASTCOPY(s, d, n) bcopy ((s), (d), (n))
# endif /* HAVE_BCOPY */
#endif /* !__GNUC__ */
@ -216,6 +217,7 @@ 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_builtin_func_t __P((WORD_LIST *)); /* sh_wlist_func_t */
@ -230,6 +232,7 @@ typedef int sh_builtin_func_t __P((WORD_LIST *)); /* sh_wlist_func_t */
#define FS_EXEC_ONLY 0x8
#define FS_DIRECTORY 0x10
#define FS_NODIRS 0x20
#define FS_READABLE 0x40
/* Default maximum for move_to_high_fd */
#define HIGH_FD_MAX 256
@ -248,14 +251,18 @@ typedef int QSFUNC ();
# define ABSPATH(x) ((x)[0] == '/')
# define RELPATH(x) ((x)[0] != '/')
#else /* __CYGWIN__ */
# define ABSPATH(x) (((x)[0] && ISALPHA((unsigned char)(x)[0]) && (x)[1] == ':' && (x)[2] == '/') || (x)[0] == '/')
# define RELPATH(x) (!(x)[0] || ((x)[1] != ':' && (x)[0] != '/'))
# define ABSPATH(x) (((x)[0] && ISALPHA((unsigned char)(x)[0]) && (x)[1] == ':') || ISDIRSEP((x)[0]))
# define RELPATH(x) (ABSPATH(x) == 0)
#endif /* __CYGWIN__ */
#define ROOTEDPATH(x) (ABSPATH(x))
#define DIRSEP '/'
#define ISDIRSEP(c) ((c) == '/')
#if !defined (__CYGWIN__)
# define ISDIRSEP(c) ((c) == '/')
#else
# define ISDIRSEP(c) ((c) == '/' || (c) == '\\')
#endif /* __CYGWIN__ */
#define PATHSEP(c) (ISDIRSEP(c) || (c) == 0)
#if 0
@ -292,10 +299,10 @@ extern int same_file __P((char *, char *, struct stat *, struct stat *));
extern int file_isdir __P((char *));
extern int file_iswdir __P((char *));
extern char *make_absolute __P((char *, char *));
extern int absolute_pathname __P((const char *));
extern int absolute_program __P((const char *));
extern char *make_absolute __P((char *, char *));
extern char *base_pathname __P((char *));
extern char *full_pathname __P((char *));
extern char *polite_directory_format __P((char *));
@ -303,6 +310,7 @@ extern char *polite_directory_format __P((char *));
extern char *extract_colon_unit __P((char *, int *));
extern void tilde_initialize __P((void));
extern char *bash_tilde_find_word __P((const char *, int, int *));
extern char *bash_tilde_expand __P((const char *, int));
extern int group_member __P((gid_t));

View file

@ -43,6 +43,9 @@ extern char *xstrchr __P((const char *, int));
#define MBSLEN(s) (((s) && (s)[0]) ? ((s)[1] ? mbstrlen (s) : 1) : 0)
#define MB_STRLEN(s) ((MB_CUR_MAX > 1) ? MBSLEN (s) : STRLEN (s))
#define MBLEN(s, n) ((MB_CUR_MAX > 1) ? mblen ((s), (n)) : 1)
#define MBRLEN(s, n, p) ((MB_CUR_MAX > 1) ? mbrlen ((s), (n), (p)) : 1)
#else /* !HANDLE_MULTIBYTE */
#undef MB_LEN_MAX
@ -61,6 +64,9 @@ extern char *xstrchr __P((const char *, int));
#define MB_STRLEN(s) (STRLEN(s))
#define MBLEN(s, n) 1
#define MBRLEN(s, n, p) 1
#endif /* !HANDLE_MULTIBYTE */
/* Declare and initialize a multibyte state. Call must be terminated

10
input.c
View file

@ -50,7 +50,7 @@ extern int errno;
if a signal is received. */
static char localbuf[128];
static int local_index, local_bufused;
static int local_index = 0, local_bufused = 0;
/* Posix and USG systems do not guarantee to restart read () if it is
interrupted by a signal. We do the read ourselves, and restart it
@ -312,7 +312,13 @@ duplicate_buffered_stream (fd1, fd2)
(bash_input.location.buffered_fd == fd2);
if (buffers[fd2])
free_buffered_stream (buffers[fd2]);
{
/* If the two objects share the same b_buffer, don't free it. */
if (buffers[fd1] && buffers[fd1]->b_buffer && buffers[fd1]->b_buffer == buffers[fd2]->b_buffer)
buffers[fd2] = (BUFFERED_STREAM *)NULL;
else
free_buffered_stream (buffers[fd2]);
}
buffers[fd2] = copy_buffered_stream (buffers[fd1]);
if (buffers[fd2])
buffers[fd2]->b_fd = fd2;

1035
jobs.c

File diff suppressed because it is too large Load diff

77
jobs.h
View file

@ -1,6 +1,6 @@
/* jobs.h -- structures and stuff used by the jobs.c file. */
/* Copyright (C) 1993-2004 Free Software Foundation, Inc.
/* Copyright (C) 1993-2005 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@ -46,9 +46,10 @@
#define PS_DONE 0
#define PS_RUNNING 1
#define PS_STOPPED 2
#define PS_RECYCLED 4
/* Each child of the shell is remembered in a STRUCT PROCESS. A chain of
such structures is a pipeline. The chain is circular. */
/* Each child of the shell is remembered in a STRUCT PROCESS. A circular
chain of such structures is a pipeline. */
typedef struct process {
struct process *next; /* Next process in the pipeline. A circular chain. */
pid_t pid; /* Process ID. */
@ -57,28 +58,44 @@ typedef struct process {
char *command; /* The particular program that is running. */
} PROCESS;
/* PRUNNING really means `not exited' */
#define PRUNNING(p) ((p)->running || WIFSTOPPED((p)->status))
/* PALIVE really means `not exited' */
#define PSTOPPED(p) (WIFSTOPPED((p)->status))
#define PDEADPROC(p) ((p)->running == PS_DONE)
#define PRUNNING(p) ((p)->running == PS_RUNNING)
#define PALIVE(p) (PRUNNING(p) || PSTOPPED(p))
#define PEXITED(p) ((p)->running == PS_DONE)
#if defined (RECYCLES_PIDS)
# define PRECYCLED(p) ((p)->running == PS_RECYCLED)
#else
# define PRECYCLED(p) (0)
#endif
#define PDEADPROC(p) (PEXITED(p) || PRECYCLED(p))
#define get_job_by_jid(ind) (jobs[(ind)])
/* A description of a pipeline's state. */
typedef enum { JRUNNING, JSTOPPED, JDEAD, JMIXED } JOB_STATE;
#define JOBSTATE(job) (jobs[(job)]->state)
#define JOBSTATE(job) (jobs[(job)]->state)
#define J_JOBSTATE(j) ((j)->state)
#define STOPPED(j) (jobs[(j)]->state == JSTOPPED)
#define RUNNING(j) (jobs[(j)]->state == JRUNNING)
#define DEADJOB(j) (jobs[(j)]->state == JDEAD)
#define INVALID_JOB(j) ((j) < 0 || (j) >= js.j_jobslots || get_job_by_jid(j) == 0)
/* Values for the FLAGS field in the JOB struct below. */
#define J_FOREGROUND 0x01 /* Non-zero if this is running in the foreground. */
#define J_NOTIFIED 0x02 /* Non-zero if already notified about job state. */
#define J_JOBCONTROL 0x04 /* Non-zero if this job started under job control. */
#define J_NOHUP 0x08 /* Don't send SIGHUP to job if shell gets SIGHUP. */
#define J_STATSAVED 0x10 /* A process in this job had had status saved via $! */
#define J_ASYNC 0x20 /* Job was started asynchronously */
#define IS_FOREGROUND(j) ((jobs[j]->flags & J_FOREGROUND) != 0)
#define IS_NOTIFIED(j) ((jobs[j]->flags & J_NOTIFIED) != 0)
#define IS_JOBCONTROL(j) ((jobs[j]->flags & J_JOBCONTROL) != 0)
#define IS_ASYNC(j) ((jobs[j]->flags & J_ASYNC) != 0)
typedef struct job {
char *wd; /* The working directory at time of invocation. */
@ -93,6 +110,42 @@ typedef struct job {
#endif /* JOB_CONTROL */
} JOB;
struct jobstats {
/* limits */
long c_childmax;
/* child process statistics */
int c_living; /* running or stopped child processes */
int c_reaped; /* exited child processes still in jobs list */
int c_injobs; /* total number of child processes in jobs list */
/* child process totals */
int c_totforked; /* total number of children this shell has forked */
int c_totreaped; /* total number of children this shell has reaped */
/* job counters and indices */
int j_jobslots; /* total size of jobs array */
int j_lastj; /* last (newest) job allocated */
int j_firstj; /* first (oldest) job allocated */
int j_njobs; /* number of non-NULL jobs in jobs array */
int j_ndead; /* number of JDEAD jobs in jobs array */
/* */
int j_current; /* current job */
int j_previous; /* previous job */
/* */
JOB *j_lastmade; /* last job allocated by stop_pipeline */
JOB *j_lastasync; /* last async job allocated by stop_pipeline */
};
struct pidstat {
struct pidstat *next;
pid_t pid;
int status;
};
struct bgpids {
struct pidstat *list;
struct pidstat *end;
int npid;
};
#define NO_JOB -1 /* An impossible job array index. */
#define DUP_JOB -2 /* A possible return value for get_job_spec (). */
#define BAD_JOBSPEC -3 /* Bad syntax for job spec. */
@ -106,12 +159,13 @@ extern pid_t fork (), getpid (), getpgrp ();
#endif /* !HAVE_UNISTD_H */
/* Stuff from the jobs.c file. */
extern struct jobstats js;
extern pid_t original_pgrp, shell_pgrp, pipeline_pgrp;
extern pid_t last_made_pid, last_asynchronous_pid;
extern int current_job, previous_job;
extern int asynchronous_notification;
extern JOB **jobs;
extern int job_slots;
extern void making_children __P((void));
extern void stop_making_children __P((void));
@ -164,9 +218,6 @@ extern int initialize_job_control __P((int));
extern void initialize_job_signals __P((void));
extern int give_terminal_to __P((pid_t, int));
extern void set_sigwinch_handler __P((void));
extern void unset_sigwinch_handler __P((void));
extern void unfreeze_jobs_list __P((void));
extern int set_job_control __P((int));
extern void without_job_control __P((void));
@ -176,6 +227,8 @@ extern void set_sigchld_handler __P((void));
extern void ignore_tty_job_signals __P((void));
extern void default_tty_job_signals __P((void));
extern void init_job_stats __P((void));
#if defined (JOB_CONTROL)
extern int job_control;
#endif

View file

@ -4,7 +4,7 @@
# #
####################################################################
#
# Copyright (C) 1996 Free Software Foundation, Inc.
# Copyright (C) 1996-2005 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

View file

@ -1,6 +1,6 @@
/* glob.c -- file-name wildcard pattern matching for Bash.
Copyright (C) 1985-2002 Free Software Foundation, Inc.
Copyright (C) 1985-2005 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
@ -66,6 +66,12 @@
# define FREE(x) if (x) free (x)
#endif
/* Don't try to alloca() more than this much memory for `struct globval'
in glob_vector() */
#ifndef ALLOCA_MAX
# define ALLOCA_MAX 100000
#endif
extern void throw_to_top_level __P((void));
extern int test_eaccess __P((char *, int));
@ -127,13 +133,13 @@ glob_pattern_p (pattern)
int r;
if (MB_CUR_MAX == 1)
return (internal_glob_pattern_p (pattern));
return (internal_glob_pattern_p ((unsigned char *)pattern));
/* Convert strings to wide chars, and call the multibyte version. */
n = xdupmbstowcs (&wpattern, NULL, pattern);
if (n == (size_t)-1)
/* Oops. Invalid multibyte sequence. Try it as single-byte sequence. */
return (internal_glob_pattern_p (pattern));
return (internal_glob_pattern_p ((unsigned char *)pattern));
r = internal_glob_wpattern_p (wpattern);
free (wpattern);
@ -347,10 +353,14 @@ glob_vector (pat, dir, flags)
register char **name_vector;
register unsigned int i;
int mflags; /* Flags passed to strmatch (). */
int nalloca;
struct globval *firstmalloc, *tmplink;
lastlink = 0;
count = lose = skip = 0;
firstmalloc = 0;
/* If PAT is empty, skip the loop, but return one (empty) filename. */
if (pat == 0 || *pat == '\0')
{
@ -488,8 +498,18 @@ glob_vector (pat, dir, flags)
if (strmatch (pat, dp->d_name, mflags) != FNM_NOMATCH)
{
if (nalloca < ALLOCA_MAX)
{
nextlink = (struct globval *) alloca (sizeof (struct globval));
nalloca += sizeof (struct globval);
}
else
{
nextlink = (struct globval *) malloc (sizeof (struct globval));
if (firstmalloc == 0)
firstmalloc = nextlink;
}
nextname = (char *) malloc (D_NAMLEN (dp) + 1);
nextlink = (struct globval *) alloca (sizeof (struct globval));
if (nextlink == 0 || nextname == 0)
{
lose = 1;
@ -515,11 +535,20 @@ glob_vector (pat, dir, flags)
/* Have we run out of memory? */
if (lose)
{
tmplink = 0;
/* Here free the strings we have got. */
while (lastlink)
{
if (firstmalloc)
{
if (lastlink == firstmalloc)
firstmalloc = 0;
tmplink = lastlink;
}
free (lastlink->name);
lastlink = lastlink->next;
FREE (tmplink);
}
QUIT;
@ -528,13 +557,29 @@ glob_vector (pat, dir, flags)
}
/* Copy the name pointers from the linked list into the vector. */
for (i = 0; i < count; ++i)
for (tmplink = lastlink, i = 0; i < count; ++i)
{
name_vector[i] = lastlink->name;
lastlink = lastlink->next;
name_vector[i] = tmplink->name;
tmplink = tmplink->next;
}
name_vector[count] = NULL;
/* If we allocated some of the struct globvals, free them now. */
if (firstmalloc)
{
tmplink = 0;
while (lastlink)
{
tmplink = lastlink;
if (lastlink == firstmalloc)
lastlink = firstmalloc = 0;
else
lastlink = lastlink->next;
free (tmplink);
}
}
return (name_vector);
}

View file

@ -1,4 +1,4 @@
/* Copyright (C) 1991-2002 Free Software Foundation, Inc.
/* Copyright (C) 1991-2005 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.

View file

@ -1,4 +1,4 @@
/* Copyright (C) 1991-2004 Free Software Foundation, Inc.
/* Copyright (C) 1991-2005 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@ -358,7 +358,7 @@ BRACKMATCH (p, test, flags)
{
bcopy (p + 1, ccname, (close - p - 1) * sizeof (CHAR));
*(ccname + (close - p - 1)) = L('\0');
pc = IS_CCLASS (test, ccname);
pc = IS_CCLASS (test, (XCHAR *)ccname);
}
if (pc == -1)
pc = 0;
@ -522,11 +522,11 @@ PATSCAN (string, end, delim)
CHAR *string, *end;
INT delim;
{
int pnest, bnest;
int pnest, bnest, skip;
INT cchar;
CHAR *s, c, *bfirst;
pnest = bnest = 0;
pnest = bnest = skip = 0;
cchar = 0;
bfirst = NULL;
@ -534,8 +534,17 @@ PATSCAN (string, end, delim)
{
if (s >= end)
return (s);
if (skip)
{
skip = 0;
continue;
}
switch (c)
{
case L('\\'):
skip = 1;
break;
case L('\0'):
return ((CHAR *)NULL);

View file

@ -1,7 +1,7 @@
/* strmatch.c -- ksh-like extended pattern matching for the shell and filename
globbing. */
/* Copyright (C) 1991-2002 Free Software Foundation, Inc.
/* Copyright (C) 1991-2005 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@ -93,14 +93,16 @@ collequiv (c1, c2)
static int
collsym (s, len)
char *s;
CHAR *s;
int len;
{
register struct _collsym *csp;
char *x;
x = (char *)s;
for (csp = posix_collsyms; csp->name; csp++)
{
if (STREQN(csp->name, s, len) && csp->name[len] == '\0')
if (STREQN(csp->name, x, len) && csp->name[len] == '\0')
return (csp->code);
}
if (len == 1)
@ -366,7 +368,7 @@ xstrmatch (pattern, string, flags)
wchar_t *wpattern, *wstring;
if (MB_CUR_MAX == 1)
return (internal_strmatch (pattern, string, flags));
return (internal_strmatch ((unsigned char *)pattern, (unsigned char *)string, flags));
n = xdupmbstowcs (&wpattern, NULL, pattern);
if (n == (size_t)-1 || n == (size_t)-2)

View file

@ -1,6 +1,6 @@
/* xmbsrtowcs.c -- replacement function for mbsrtowcs */
/* Copyright (C) 2002 Free Software Foundation, Inc.
/* Copyright (C) 2002-2004 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@ -54,7 +54,7 @@ xmbsrtowcs (dest, src, len, pstate)
ps = &local_state;
}
n = strlen(*src);
n = strlen (*src);
if (dest == NULL)
{
@ -62,19 +62,22 @@ xmbsrtowcs (dest, src, len, pstate)
const char *mbs;
mbstate_t psbuf;
/* It doesn't matter if malloc fails here, since mbsrtowcs should do
the right thing with a NULL first argument. */
wsbuf = (wchar_t *) malloc ((n + 1) * sizeof(wchar_t));
mbs = *src;
psbuf = *ps;
wclength = mbsrtowcs (wsbuf, &mbs, n, &psbuf);
free (wsbuf);
if (wsbuf)
free (wsbuf);
return wclength;
}
for (wclength = 0; wclength < len; wclength++, dest++)
{
if(mbsinit(ps))
if (mbsinit(ps))
{
if (**src == '\0')
{
@ -166,10 +169,11 @@ xdupmbstowcs (destp, indicesp, src)
p = src;
wcnum = 0;
do {
do
{
size_t mblength; /* Byte length of one multibyte character. */
if(mbsinit (&state))
if (mbsinit (&state))
{
if (*p == '\0')
{
@ -230,7 +234,8 @@ xdupmbstowcs (destp, indicesp, src)
wsbuf[wcnum - 1] = wc;
indices[wcnum - 1] = (char *)p;
p += mblength;
} while (MB_NULLWCH (wc) == 0);
}
while (MB_NULLWCH (wc) == 0);
/* Return the length of the wide character string, not including `\0'. */
*destp = wsbuf;

View file

@ -51,12 +51,14 @@ RANLIB = @RANLIB@
YACC = @INTLBISON@ -y -d
YFLAGS = --name-prefix=__gettext
LOCAL_DEFS = @LOCAL_DEFS@
DEFS = -DLOCALEDIR=\"$(localedir)\" -DLOCALE_ALIAS_PATH=\"$(aliaspath)\" \
-DLIBDIR=\"$(prefix)/libdata\" -DIN_LIBINTL \
-DENABLE_RELOCATABLE=1 -DIN_LIBRARY -DINSTALLDIR=\"$(libdir)\" -DNO_XMALLOC \
-Dset_relocation_prefix=libintl_set_relocation_prefix \
-Drelocate=libintl_relocate \
-DDEPENDS_ON_LIBICONV=1 @DEFS@
-DDEPENDS_ON_LIBICONV=1 @DEFS@ @LOCAL_DEFS@
CPPFLAGS = @CPPFLAGS@
CFLAGS = @CFLAGS@
LDFLAGS = @LDFLAGS@

View file

@ -134,6 +134,10 @@ extern int errno;
/* @@ end of prolog @@ */
#if defined (SHELL) && !defined (HAVE_GETCWD)
# define HAVE_GETCWD
#endif
#ifdef _LIBC
/* Rename the non ANSI C functions. This is required by the standard
because some ANSI C functions will require linking with this object
@ -417,6 +421,10 @@ static int enable_secure;
}
#endif
#ifndef HAVE_RAISE
# define raise(x) kill (getpid (), (x))
#endif
/* Get the function to evaluate the plural expression. */
#include "eval-plural.h"

View file

@ -1,7 +1,7 @@
# Skeleton Makefile for the GNU malloc code
#
#
# Copyright (C) 1996 Free Software Foundation, Inc.
# Copyright (C) 1996-2005 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
@ -115,6 +115,7 @@ 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
table.o: ${BUILD_DIR}/config.h
watch.o: ${BUILD_DIR}/config.h
malloc.o: ${srcdir}/imalloc.h ${srcdir}/mstats.h
malloc.o: ${srcdir}/table.h ${srcdir}/watch.h

View file

@ -1,6 +1,6 @@
/* malloc.c - dynamic memory allocation for bash. */
/* Copyright (C) 1985-2003 Free Software Foundation, Inc.
/* Copyright (C) 1985-2005 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
@ -221,7 +221,7 @@ typedef union _malloc_guard {
static union mhead *nextf[NBUCKETS];
/* busy[i] is nonzero while allocation of block size i is in progress. */
/* busy[i] is nonzero while allocation or free of block size i is in progress. */
static char busy[NBUCKETS];
@ -246,7 +246,7 @@ static unsigned long binsizes[NBUCKETS] = {
static PTR_T internal_malloc __P((size_t, const char *, int, int));
static PTR_T internal_realloc __P((PTR_T, size_t, const char *, int, int));
static void internal_free __P((PTR_T, const char *, int, int));
static PTR_T internal_memalign __P((unsigned int, size_t, const char *, int, int));
static PTR_T internal_memalign __P((size_t, size_t, const char *, int, int));
#ifndef NO_CALLOC
static PTR_T internal_calloc __P((size_t, size_t, const char *, int, int));
static void internal_cfree __P((PTR_T, const char *, int, int));
@ -323,7 +323,8 @@ xbotch (mem, e, s, file, line)
/* Coalesce two adjacent free blocks off the free list for size NU - 1,
as long as we can find two adjacent free blocks. nextf[NU -1] is
assumed to not be busy; the caller (morecore()) checks for this. */
assumed to not be busy; the caller (morecore()) checks for this.
BUSY[NU] must be set to 1. */
static void
bcoalesce (nu)
register int nu;
@ -333,9 +334,10 @@ bcoalesce (nu)
unsigned long siz;
nbuck = nu - 1;
if (nextf[nbuck] == 0)
if (nextf[nbuck] == 0 || busy[nbuck])
return;
busy[nbuck] = 1;
siz = binsize (nbuck);
mp2 = mp1 = nextf[nbuck];
@ -346,22 +348,27 @@ bcoalesce (nu)
mp1 = mp;
mp = CHAIN (mp);
}
if (mp == 0)
return;
{
busy[nbuck] = 0;
return;
}
/* OK, now we have mp1 pointing to the block we want to add to nextf[NU].
CHAIN(mp2) must equal mp1. Check that mp1 and mp are adjacent. */
if (mp2 != mp1 && CHAIN(mp2) != mp1)
xbotch ((PTR_T)0, 0, "bcoalesce: CHAIN(mp2) != mp1", (char *)NULL, 0);
{
busy[nbuck] = 0;
xbotch ((PTR_T)0, 0, "bcoalesce: CHAIN(mp2) != mp1", (char *)NULL, 0);
}
#ifdef MALLOC_DEBUG
if (CHAIN (mp1) != (union mhead *)((char *)mp1 + siz))
return; /* not adjacent */
#endif
#ifdef MALLOC_STATS
_mstats.tbcoalesce++;
_mstats.ncoalesce[nbuck]++;
{
busy[nbuck] = 0;
return; /* not adjacent */
}
#endif
/* Since they are adjacent, remove them from the free list */
@ -369,6 +376,12 @@ bcoalesce (nu)
nextf[nbuck] = CHAIN (mp);
else
CHAIN (mp2) = CHAIN (mp);
busy[nbuck] = 0;
#ifdef MALLOC_STATS
_mstats.tbcoalesce++;
_mstats.ncoalesce[nbuck]++;
#endif
/* And add the combined two blocks to nextf[NU]. */
mp1->mh_alloc = ISFREE;
@ -380,7 +393,7 @@ bcoalesce (nu)
/* Split a block at index > NU (but less than SPLIT_MAX) into a set of
blocks of the correct size, and attach them to nextf[NU]. nextf[NU]
is assumed to be empty. Must be called with signals blocked (e.g.,
by morecore()). */
by morecore()). BUSY[NU] must be set to 1. */
static void
bsplit (nu)
register int nu;
@ -416,6 +429,12 @@ bsplit (nu)
/* XXX might want to split only if nextf[nbuck] has >= 2 blocks free
and nbuck is below some threshold. */
/* Remove the block from the chain of larger blocks. */
busy[nbuck] = 1;
mp = nextf[nbuck];
nextf[nbuck] = CHAIN (mp);
busy[nbuck] = 0;
#ifdef MALLOC_STATS
_mstats.tbsplit++;
_mstats.nsplit[nbuck]++;
@ -425,10 +444,6 @@ bsplit (nu)
siz = binsize (nu);
nblks = binsize (nbuck) / siz;
/* Remove the block from the chain of larger blocks. */
mp = nextf[nbuck];
nextf[nbuck] = CHAIN (mp);
/* Split the block and put it on the requested chain. */
nextf[nu] = mp;
while (1)
@ -442,6 +457,49 @@ bsplit (nu)
CHAIN (mp) = 0;
}
/* Take the memory block MP and add it to a chain < NU. NU is the right bucket,
but is busy. This avoids memory orphaning. */
static void
xsplit (mp, nu)
union mhead *mp;
int nu;
{
union mhead *nh;
int nbuck, nblks, split_max;
unsigned long siz;
nbuck = nu - 1;
while (nbuck >= SPLIT_MIN && busy[nbuck])
nbuck--;
if (nbuck < SPLIT_MIN)
return;
#ifdef MALLOC_STATS
_mstats.tbsplit++;
_mstats.nsplit[nu]++;
#endif
/* Figure out how many blocks we'll get. */
siz = binsize (nu); /* original block size */
nblks = siz / binsize (nbuck); /* should be 2 most of the time */
/* And add it to nextf[nbuck] */
siz = binsize (nbuck); /* XXX - resetting here */
nh = mp;
while (1)
{
mp->mh_alloc = ISFREE;
mp->mh_index = nbuck;
if (--nblks <= 0) break;
CHAIN (mp) = (union mhead *)((char *)mp + siz);
mp = (union mhead *)((char *)mp + siz);
}
busy[nbuck] = 1;
CHAIN (mp) = nextf[nbuck];
nextf[nbuck] = nh;
busy[nbuck] = 0;
}
static void
block_signals (setp, osetp)
sigset_t *setp, *osetp;
@ -490,9 +548,10 @@ lesscore (nu) /* give system back some memory */
_mstats.nlesscore[nu]++;
#endif
}
/* Ask system for more memory; add to NEXTF[NU]. BUSY[NU] must be set to 1. */
static void
morecore (nu) /* ask system for more memory */
morecore (nu)
register int nu; /* size index to get more of */
{
register union mhead *mp;
@ -531,7 +590,7 @@ morecore (nu) /* ask system for more memory */
}
/* Try to coalesce two adjacent blocks from the free list on nextf[nu - 1],
if we can, and we're withing the range of the block coalescing limits. */
if we can, and we're within the range of the block coalescing limits. */
if (nu >= COMBINE_MIN && nu < COMBINE_MAX && busy[nu - 1] == 0 && nextf[nu - 1])
{
bcoalesce (nu);
@ -852,9 +911,8 @@ internal_free (mem, file, line, flags)
{
/* If above LESSCORE_FRC, give back unconditionally. This should be set
high enough to be infrequently encountered. If between LESSCORE_MIN
and LESSCORE_FRC, call lesscore if the bucket is marked as busy (in
which case we would punt below and leak memory) or if there's already
a block on the free list. */
and LESSCORE_FRC, call lesscore if the bucket is marked as busy or if
there's already a block on the free list. */
if ((nunits >= LESSCORE_FRC) || busy[nunits] || nextf[nunits] != 0)
{
lesscore (nunits);
@ -869,11 +927,14 @@ internal_free (mem, file, line, flags)
#endif
ASSERT (nunits < NBUCKETS);
p->mh_alloc = ISFREE;
if (busy[nunits] == 1)
return; /* this is bogus, but at least it won't corrupt the chains */
{
xsplit (p, nunits); /* split block and add to different chain */
goto free_return;
}
p->mh_alloc = ISFREE;
/* Protect against signal handlers calling malloc. */
busy[nunits] = 1;
/* Put this block on the free list. */
@ -1026,7 +1087,7 @@ internal_realloc (mem, n, file, line, flags)
static PTR_T
internal_memalign (alignment, size, file, line, flags)
unsigned int alignment;
size_t alignment;
size_t size;
const char *file;
int line, flags;
@ -1145,7 +1206,7 @@ sh_free (mem, file, line)
PTR_T
sh_memalign (alignment, size, file, line)
unsigned int alignment;
size_t alignment;
size_t size;
const char *file;
int line;
@ -1212,7 +1273,7 @@ free (mem)
PTR_T
memalign (alignment, size)
unsigned int alignment;
size_t alignment;
size_t size;
{
return internal_memalign (alignment, size, (char *)NULL, 0, 0);

View file

@ -43,7 +43,7 @@ extern PTR_T sh_malloc __P((size_t, const char *, int));
extern PTR_T sh_realloc __P((PTR_T, size_t, const char *, int));
extern void sh_free __P((PTR_T, const char *, int));
extern PTR_T sh_memalign __P((unsigned int, size_t, const char *, int));
extern PTR_T sh_memalign __P((size_t, size_t, const char *, int));
extern PTR_T sh_calloc __P((size_t, size_t, const char *, int));
extern void sh_cfree __P((PTR_T, const char *, int));

View file

@ -22,6 +22,9 @@
#endif
#include <stdio.h>
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#include "imalloc.h"
@ -29,10 +32,10 @@ extern int malloc_trace;
static int _mtrace_verbose = 0;
extern FILE *_imalloc_fopen __P((char *, char *, char *, char *, size_t));
#ifdef MALLOC_TRACE
extern FILE *_imalloc_fopen __P((char *, char *, char *, char *, size_t));
FILE *_mtrace_fp = NULL;
extern char _malloc_trace_buckets[];

View file

@ -4,7 +4,7 @@
# #
#############################################################################
# Copyright (C) 1994 Free Software Foundation, Inc.
# Copyright (C) 1994-2005 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

View file

@ -1,6 +1,6 @@
/* bind.c -- key binding and startup file support for the readline library. */
/* Copyright (C) 1987, 1989, 1992 Free Software Foundation, Inc.
/* Copyright (C) 1987-2005 Free Software Foundation, Inc.
This file is part of the GNU Readline Library, a library for
reading lines of text with interactive input and history editing.
@ -77,6 +77,9 @@ static char *_rl_read_file PARAMS((char *, size_t *));
static void _rl_init_file_error PARAMS((const char *));
static int _rl_read_init_file PARAMS((const char *, int));
static int glean_key_from_name PARAMS((char *));
static int find_boolean_var PARAMS((const char *));
static char *_rl_get_string_variable_value PARAMS((const char *));
static int substring_member_of_array PARAMS((char *, const char **));
static int currently_reading_init_file;
@ -341,7 +344,7 @@ rl_generic_bind (type, keyseq, data, map)
k.function = 0;
/* If no keys to bind to, exit right away. */
if (!keyseq || !*keyseq)
if (keyseq == 0 || *keyseq == 0)
{
if (type == ISMACR)
free (data);
@ -369,7 +372,7 @@ rl_generic_bind (type, keyseq, data, map)
if (ic < 0 || ic >= KEYMAP_SIZE)
return -1;
if (_rl_convert_meta_chars_to_ascii && META_CHAR (ic))
if (META_CHAR (ic) && _rl_convert_meta_chars_to_ascii)
{
ic = UNMETA (ic);
if (map[ESC].type == ISKMAP)
@ -460,7 +463,14 @@ rl_translate_keyseq (seq, array, len)
else if (c == 'M')
{
i++;
array[l++] = ESC; /* ESC is meta-prefix */
/* XXX - should obey convert-meta setting? */
if (_rl_convert_meta_chars_to_ascii && _rl_keymap[ESC].type == ISKMAP)
array[l++] = ESC; /* ESC is meta-prefix */
else
{
i++;
array[l++] = META (seq[i]);
}
}
else if (c == 'C')
{
@ -1185,9 +1195,9 @@ rl_parse_and_bind (string)
/* If this is a command to set a variable, then do that. */
if (_rl_stricmp (string, "set") == 0)
{
char *var = string + i;
char *value;
char *var, *value, *e;
var = string + i;
/* Make VAR point to start of variable name. */
while (*var && whitespace (*var)) var++;
@ -1198,6 +1208,20 @@ rl_parse_and_bind (string)
*value++ = '\0';
while (*value && whitespace (*value)) value++;
/* Strip trailing whitespace from values to boolean variables. Temp
fix until I get a real quoted-string parser here. */
i = find_boolean_var (var);
if (i >= 0)
{
/* remove trailing whitespace */
e = value + strlen (value) - 1;
while (e >= value && whitespace (*e))
e--;
e++; /* skip back to whitespace or EOS */
if (*e && e >= value)
*e = '\0';
}
rl_variable_bind (var, value);
return 0;
}
@ -1218,8 +1242,9 @@ rl_parse_and_bind (string)
the quoted string delimiter, like the shell. */
if (*funname == '\'' || *funname == '"')
{
int delimiter = string[i++], passc;
int delimiter, passc;
delimiter = string[i++];
for (passc = 0; c = string[i]; i++)
{
if (passc)
@ -1355,6 +1380,7 @@ static struct {
int *value;
int flags;
} boolean_varlist [] = {
{ "bind-tty-special-chars", &_rl_bind_stty_chars, 0 },
{ "blink-matching-paren", &rl_blink_matching_paren, V_SPECIAL },
{ "byte-oriented", &rl_byte_oriented, 0 },
{ "completion-ignore-case", &_rl_completion_case_fold, 0 },
@ -1468,13 +1494,34 @@ find_string_var (name)
values result in 0 (false). */
static int
bool_to_int (value)
char *value;
const char *value;
{
return (value == 0 || *value == '\0' ||
(_rl_stricmp (value, "on") == 0) ||
(value[0] == '1' && value[1] == '\0'));
}
char *
rl_variable_value (name)
const char *name;
{
register int i;
int v;
char *ret;
/* Check for simple variables first. */
i = find_boolean_var (name);
if (i >= 0)
return (*boolean_varlist[i].value ? "on" : "off");
i = find_string_var (name);
if (i >= 0)
return (_rl_get_string_variable_value (string_varlist[i].name));
/* Unknown variable names return NULL. */
return 0;
}
int
rl_variable_bind (name, value)
const char *name, *value;
@ -2117,12 +2164,68 @@ rl_dump_macros (count, key)
return (0);
}
static char *
_rl_get_string_variable_value (name)
const char *name;
{
static char numbuf[32];
char *ret;
int n;
if (_rl_stricmp (name, "bell-style") == 0)
{
switch (_rl_bell_preference)
{
case NO_BELL:
return "none";
case VISIBLE_BELL:
return "visible";
case AUDIBLE_BELL:
default:
return "audible";
}
}
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-query-items") == 0)
{
sprintf (numbuf, "%d", rl_completion_query_items);
return (numbuf);
}
else if (_rl_stricmp (name, "editing-mode") == 0)
return (rl_get_keymap_name_from_edit_mode ());
else if (_rl_stricmp (name, "isearch-terminators") == 0)
{
if (_rl_isearch_terminators == 0)
return 0;
ret = _rl_untranslate_macro_value (_rl_isearch_terminators);
if (ret)
{
strncpy (numbuf, ret, sizeof (numbuf) - 1);
free (ret);
numbuf[sizeof(numbuf) - 1] = '\0';
}
else
numbuf[0] = '\0';
return numbuf;
}
else if (_rl_stricmp (name, "keymap") == 0)
{
ret = rl_get_keymap_name (_rl_keymap);
if (ret == 0)
ret = rl_get_keymap_name_from_edit_mode ();
return (ret ? ret : "none");
}
else
return (0);
}
void
rl_variable_dumper (print_readably)
int print_readably;
{
int i;
const char *kname;
char *v;
for (i = 0; boolean_varlist[i].name; i++)
{
@ -2134,63 +2237,16 @@ rl_variable_dumper (print_readably)
*boolean_varlist[i].value ? "on" : "off");
}
/* bell-style */
switch (_rl_bell_preference)
for (i = 0; string_varlist[i].name; i++)
{
case NO_BELL:
kname = "none"; break;
case VISIBLE_BELL:
kname = "visible"; break;
case AUDIBLE_BELL:
default:
kname = "audible"; break;
}
if (print_readably)
fprintf (rl_outstream, "set bell-style %s\n", kname);
else
fprintf (rl_outstream, "bell-style is set to `%s'\n", kname);
/* comment-begin */
if (print_readably)
fprintf (rl_outstream, "set comment-begin %s\n", _rl_comment_begin ? _rl_comment_begin : RL_COMMENT_BEGIN_DEFAULT);
else
fprintf (rl_outstream, "comment-begin is set to `%s'\n", _rl_comment_begin ? _rl_comment_begin : RL_COMMENT_BEGIN_DEFAULT);
/* completion-query-items */
if (print_readably)
fprintf (rl_outstream, "set completion-query-items %d\n", rl_completion_query_items);
else
fprintf (rl_outstream, "completion-query-items is set to `%d'\n", rl_completion_query_items);
/* editing-mode */
if (print_readably)
fprintf (rl_outstream, "set editing-mode %s\n", (rl_editing_mode == emacs_mode) ? "emacs" : "vi");
else
fprintf (rl_outstream, "editing-mode is set to `%s'\n", (rl_editing_mode == emacs_mode) ? "emacs" : "vi");
/* isearch-terminators */
if (_rl_isearch_terminators)
{
char *disp;
disp = _rl_untranslate_macro_value (_rl_isearch_terminators);
v = _rl_get_string_variable_value (string_varlist[i].name);
if (v == 0) /* _rl_isearch_terminators can be NULL */
continue;
if (print_readably)
fprintf (rl_outstream, "set isearch-terminators \"%s\"\n", disp);
fprintf (rl_outstream, "set %s %s\n", string_varlist[i].name, v);
else
fprintf (rl_outstream, "isearch-terminators is set to \"%s\"\n", disp);
free (disp);
fprintf (rl_outstream, "%s is set to `%s'\n", string_varlist[i].name, v);
}
/* keymap */
kname = rl_get_keymap_name (_rl_keymap);
if (kname == 0)
kname = rl_get_keymap_name_from_edit_mode ();
if (print_readably)
fprintf (rl_outstream, "set keymap %s\n", kname ? kname : "none");
else
fprintf (rl_outstream, "keymap is set to `%s'\n", kname ? kname : "none");
}
/* Print all of the current variables and their values to

View file

@ -1,6 +1,6 @@
/* callback.c -- functions to use readline as an X `callback' mechanism. */
/* Copyright (C) 1987, 1989, 1992 Free Software Foundation, Inc.
/* Copyright (C) 1987-2005 Free Software Foundation, Inc.
This file is part of the GNU Readline Library, a library for
reading lines of text with interactive input and history editing.
@ -44,9 +44,14 @@
#include "readline.h"
#include "rlprivate.h"
/* Private data for callback registration functions. See comments in
rl_callback_read_char for more details. */
_rl_callback_func_t *_rl_callback_func = 0;
_rl_callback_generic_arg *_rl_callback_data = 0;
/* **************************************************************** */
/* */
/* Callback Readline Functions */
/* Callback Readline Functions */
/* */
/* **************************************************************** */
@ -72,7 +77,8 @@ _rl_callback_newline ()
{
in_handler = 1;
(*rl_prep_term_function) (_rl_meta_flag);
if (rl_prep_term_function)
(*rl_prep_term_function) (_rl_meta_flag);
#if defined (HANDLE_SIGNALS)
rl_set_signals ();
@ -89,6 +95,7 @@ rl_callback_handler_install (prompt, linefunc)
rl_vcpfunc_t *linefunc;
{
rl_set_prompt (prompt);
RL_SETSTATE (RL_STATE_CALLBACK);
rl_linefunc = linefunc;
_rl_callback_newline ();
}
@ -98,7 +105,8 @@ void
rl_callback_read_char ()
{
char *line;
int eof;
int eof, jcode;
static procenv_t olevel;
if (rl_linefunc == NULL)
{
@ -106,7 +114,79 @@ rl_callback_read_char ()
abort ();
}
eof = readline_internal_char ();
memcpy ((void *)olevel, (void *)readline_top_level, sizeof (procenv_t));
jcode = setjmp (readline_top_level);
if (jcode)
{
(*rl_redisplay_function) ();
_rl_want_redisplay = 0;
memcpy ((void *)readline_top_level, (void *)olevel, sizeof (procenv_t));
return;
}
if (RL_ISSTATE (RL_STATE_ISEARCH))
{
eof = _rl_isearch_callback (_rl_iscxt);
if (eof == 0 && (RL_ISSTATE (RL_STATE_ISEARCH) == 0) && RL_ISSTATE (RL_STATE_INPUTPENDING))
rl_callback_read_char ();
return;
}
else if (RL_ISSTATE (RL_STATE_NSEARCH))
{
eof = _rl_nsearch_callback (_rl_nscxt);
return;
}
else if (RL_ISSTATE (RL_STATE_NUMERICARG))
{
eof = _rl_arg_callback (_rl_argcxt);
if (eof == 0 && (RL_ISSTATE (RL_STATE_NUMERICARG) == 0) && RL_ISSTATE (RL_STATE_INPUTPENDING))
rl_callback_read_char ();
/* XXX - this should handle _rl_last_command_was_kill better */
else if (RL_ISSTATE (RL_STATE_NUMERICARG) == 0)
_rl_internal_char_cleanup ();
return;
}
else if (RL_ISSTATE (RL_STATE_MULTIKEY))
{
eof = _rl_dispatch_callback (_rl_kscxt); /* For now */
while ((eof == -1 || eof == -2) && RL_ISSTATE (RL_STATE_MULTIKEY) && _rl_kscxt && (_rl_kscxt->flags & KSEQ_DISPATCHED))
eof = _rl_dispatch_callback (_rl_kscxt);
if (RL_ISSTATE (RL_STATE_MULTIKEY) == 0)
{
_rl_internal_char_cleanup ();
_rl_want_redisplay = 1;
}
}
else if (_rl_callback_func)
{
/* This allows functions that simply need to read an additional character
(like quoted-insert) to register a function to be called when input is
available. _rl_callback_data is simply a pointer to a struct that has
the argument count originally passed to the registering function and
space for any additional parameters. */
eof = (*_rl_callback_func) (_rl_callback_data);
/* If the function `deregisters' itself, make sure the data is cleaned
up. */
if (_rl_callback_func == 0)
{
if (_rl_callback_data)
{
_rl_callback_data_dispose (_rl_callback_data);
_rl_callback_data = 0;
}
_rl_internal_char_cleanup ();
}
}
else
eof = readline_internal_char ();
if (rl_done == 0 && _rl_want_redisplay)
{
(*rl_redisplay_function) ();
_rl_want_redisplay = 0;
}
/* We loop in case some function has pushed input back with rl_execute_next. */
for (;;)
@ -115,7 +195,8 @@ rl_callback_read_char ()
{
line = readline_internal_teardown (eof);
(*rl_deprep_term_function) ();
if (rl_deprep_term_function)
(*rl_deprep_term_function) ();
#if defined (HANDLE_SIGNALS)
rl_clear_signals ();
#endif
@ -131,10 +212,10 @@ rl_callback_read_char ()
if (in_handler == 0 && rl_linefunc)
_rl_callback_newline ();
}
if (rl_pending_input || _rl_pushed_input_available ())
if (rl_pending_input || _rl_pushed_input_available () || RL_ISSTATE (RL_STATE_MACROINPUT))
eof = readline_internal_char ();
else
break;
break;
}
}
@ -143,14 +224,37 @@ void
rl_callback_handler_remove ()
{
rl_linefunc = NULL;
RL_UNSETSTATE (RL_STATE_CALLBACK);
if (in_handler)
{
in_handler = 0;
(*rl_deprep_term_function) ();
if (rl_deprep_term_function)
(*rl_deprep_term_function) ();
#if defined (HANDLE_SIGNALS)
rl_clear_signals ();
#endif
}
}
_rl_callback_generic_arg *
_rl_callback_data_alloc (count)
int count;
{
_rl_callback_generic_arg *arg;
arg = (_rl_callback_generic_arg *)xmalloc (sizeof (_rl_callback_generic_arg));
arg->count = count;
arg->i1 = arg->i2 = 0;
return arg;
}
void _rl_callback_data_dispose (arg)
_rl_callback_generic_arg *arg;
{
if (arg)
free (arg);
}
#endif

View file

@ -86,6 +86,8 @@
/* Some systems define these; we want our definitions. */
#undef ISPRINT
/* Beware: these only work with single-byte ASCII characters. */
#define ISALNUM(c) (IN_CTYPE_DOMAIN (c) && isalnum (c))
#define ISALPHA(c) (IN_CTYPE_DOMAIN (c) && isalpha (c))
#define ISDIGIT(c) (IN_CTYPE_DOMAIN (c) && isdigit (c))

View file

@ -1,6 +1,6 @@
/* complete.c -- filename completion for readline. */
/* Copyright (C) 1987-2004 Free Software Foundation, Inc.
/* Copyright (C) 1987-2005 Free Software Foundation, Inc.
This file is part of the GNU Readline Library, a library for
reading lines of text with interactive input and history editing.
@ -48,7 +48,9 @@
extern int errno;
#endif /* !errno */
#if defined (HAVE_PWD_H)
#include <pwd.h>
#endif
#include "posixdir.h"
#include "posixstat.h"
@ -79,9 +81,9 @@ typedef int QSFUNC ();
/* Most systems don't declare getpwent in <pwd.h> if _POSIX_SOURCE is
defined. */
#if !defined (HAVE_GETPW_DECLS) || defined (_POSIX_SOURCE)
#if defined (HAVE_GETPWENT) && (!defined (HAVE_GETPW_DECLS) || defined (_POSIX_SOURCE))
extern struct passwd *getpwent PARAMS((void));
#endif /* !HAVE_GETPW_DECLS || _POSIX_SOURCE */
#endif /* HAVE_GETPWENT && (!HAVE_GETPW_DECLS || _POSIX_SOURCE) */
/* If non-zero, then this is the address of a function to call when
completing a word would normally display the list of possible matches.
@ -206,7 +208,8 @@ int rl_completion_type = 0;
/* Up to this many items will be displayed in response to a
possible-completions call. After that, we ask the user if
she is sure she wants to see them all. */
she is sure she wants to see them all. A negative value means
don't ask. */
int rl_completion_query_items = 100;
int _rl_page_completions = 1;
@ -621,6 +624,8 @@ fnprint (to_print)
mbstate_t ps;
const char *end;
size_t tlen;
int width, w;
wchar_t wc;
end = to_print + strlen (to_print) + 1;
memset (&ps, 0, sizeof (mbstate_t));
@ -653,21 +658,28 @@ fnprint (to_print)
else
{
#if defined (HANDLE_MULTIBYTE)
tlen = mbrlen (s, end - s, &ps);
tlen = mbrtowc (&wc, s, end - s, &ps);
if (MB_INVALIDCH (tlen))
{
tlen = 1;
width = 1;
memset (&ps, 0, sizeof (mbstate_t));
}
else if (MB_NULLWCH (tlen))
break;
else
{
w = wcwidth (wc);
width = (w >= 0) ? w : 1;
}
fwrite (s, 1, tlen, rl_outstream);
s += tlen;
printed_len += width;
#else
putc (*s, rl_outstream);
s++;
#endif
printed_len++;
#endif
}
}
@ -683,7 +695,7 @@ print_filename (to_print, full_pathname)
char *to_print, *full_pathname;
{
int printed_len, extension_char, slen, tlen;
char *s, c, *new_full_pathname;
char *s, c, *new_full_pathname, *dn;
extension_char = 0;
printed_len = fnprint (to_print);
@ -708,7 +720,17 @@ print_filename (to_print, full_pathname)
files in the root directory. If we pass a null string to the
bash directory completion hook, for example, it will expand it
to the current directory. We just want the `/'. */
s = tilde_expand (full_pathname && *full_pathname ? full_pathname : "/");
if (full_pathname == 0 || *full_pathname == 0)
dn = "/";
else if (full_pathname[0] != '/')
dn = full_pathname;
else if (full_pathname[1] == 0)
dn = "//"; /* restore trailing slash to `//' */
else if (full_pathname[1] == '/' && full_pathname[2] == 0)
dn = "/"; /* don't turn /// into // */
else
dn = full_pathname;
s = tilde_expand (dn);
if (rl_directory_completion_hook)
(*rl_directory_completion_hook) (&s);
@ -716,6 +738,10 @@ print_filename (to_print, full_pathname)
tlen = strlen (to_print);
new_full_pathname = (char *)xmalloc (slen + tlen + 2);
strcpy (new_full_pathname, s);
if (s[slen - 1] == '/')
slen--;
else
new_full_pathname[slen] = '/';
new_full_pathname[slen] = '/';
strcpy (new_full_pathname + slen + 1, to_print);
@ -807,14 +833,7 @@ _rl_find_completion_word (fp, dp)
quote substrings for the completer. Try to find the start
of an unclosed quoted substring. */
/* FOUND_QUOTE is set so we know what kind of quotes we found. */
#if defined (HANDLE_MULTIBYTE)
for (scan = pass_next = 0; scan < end;
scan = ((MB_CUR_MAX == 1 || rl_byte_oriented)
? (scan + 1)
: _rl_find_next_mbchar (rl_line_buffer, scan, 1, MB_FIND_ANY)))
#else
for (scan = pass_next = 0; scan < end; scan++)
#endif
for (scan = pass_next = 0; scan < end; scan = MB_NEXTCHAR (rl_line_buffer, scan, 1, MB_FIND_ANY))
{
if (pass_next)
{
@ -864,11 +883,7 @@ _rl_find_completion_word (fp, dp)
/* We didn't find an unclosed quoted substring upon which to do
completion, so use the word break characters to find the
substring on which to complete. */
#if defined (HANDLE_MULTIBYTE)
while (rl_point = _rl_find_prev_mbchar (rl_line_buffer, rl_point, MB_FIND_ANY))
#else
while (--rl_point)
#endif
while (rl_point = MB_PREVCHAR (rl_line_buffer, rl_point, MB_FIND_ANY))
{
scan = rl_line_buffer[rl_point];
@ -1151,7 +1166,7 @@ compute_lcd_of_matches (match_list, matches, text)
rl_completion_found_quote &&
rl_filename_quoting_desired)
{
dtext = (*rl_filename_dequoting_function) (text, rl_completion_quote_character);
dtext = (*rl_filename_dequoting_function) ((char *)text, rl_completion_quote_character);
text = dtext;
}
@ -1397,7 +1412,7 @@ display_matches (matches)
/* If there are many items, then ask the user if she really wants to
see them all. */
if (len >= rl_completion_query_items)
if (rl_completion_query_items > 0 && len >= rl_completion_query_items)
{
rl_crlf ();
fprintf (rl_outstream, "Display all %d possibilities? (y or n)", len);
@ -1534,7 +1549,7 @@ append_to_match (text, delimiter, quote_char, nontrivial_match)
: stat (filename, &finfo);
if (s == 0 && S_ISDIR (finfo.st_mode))
{
if (_rl_complete_mark_directories)
if (_rl_complete_mark_directories /* && rl_completion_suppress_append == 0 */)
{
/* This is clumsy. Avoid putting in a double slash if point
is at the end of the line and the previous character is a
@ -1848,16 +1863,20 @@ rl_username_completion_function (text, state)
setpwent ();
}
#if defined (HAVE_GETPWENT)
while (entry = getpwent ())
{
/* Null usernames should result in all users as possible completions. */
if (namelen == 0 || (STREQN (username, entry->pw_name, namelen)))
break;
}
#endif
if (entry == 0)
{
#if defined (HAVE_GETPWENT)
endpwent ();
#endif
return ((char *)NULL);
}
else
@ -2169,9 +2188,11 @@ rl_menu_complete (count, ignore)
return (0);
}
match_list_index = (match_list_index + count) % match_list_size;
match_list_index += count;
if (match_list_index < 0)
match_list_index += match_list_size;
else
match_list_index %= match_list_size;
if (match_list_index == 0 && match_list_size > 1)
{

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