commit bash-20141017 snapshot

This commit is contained in:
Chet Ramey
2014-10-21 12:07:41 -04:00
parent d36d2bcf27
commit b4a0002219
20 changed files with 2164 additions and 1887 deletions
+63
View File
@@ -6957,3 +6957,66 @@ execute_cmd.c
when entering a function so break and continue in functions don't
break loops running outside of the function. Fix picked up from
dash via Herbert Xu <herbert@gnodor.apana.org.au>
10/13
-----
doc/Makefile.in
- bashref.pdf: create using texi2dvi --pdf rather than postprocessing the
dvi file, so we have PDF bookmarks and links. Fix from
Siep Kroonenberg <siepo@cybercomm.nl>
10/14
-----
subst.h
- Q_ARITH: new quoting flag. Semantics are per Posix's spec for arithmetic
expansion: act as if string is quoted, but don't treat double quotes
specially (in this case, they will be removed by quote removal)
- Q_ARRAYSUB: new quoting flag, indicates we are expanding an indexed array
subscript
subst.c
- expand_arith_string: if we are not expanding the string, but we saw a quote
with Q_ARITH specified as one of quoting flags, perform quote removal even
if Q_DOUBLE_QUOTES is specified
- param_expand: change calls to expand_arith_string for $[ and $(( cases to
specify Q_ARITH. Now $(( "$x" )) and $(( "x" )) work if x has a value that
evaluates to a valid number, as Posix specifies
- expand_word_internal: add test for quoted&Q_ARITH to the tilde case, so we
continue to perform tilde expansion in arithmetic contexts
- expand_word_internal: if quoted&Q_ARITH, continue processing when we see a
`"', acting as if the double quote isn't present (already Q_DOUBLE_QUOTED)
arrayfunc.c
- array_expand_index: pass Q_DOUBLE_QUOTED|Q_ARITH|Q_ARRAYSUB as quoted argument
in call to expand_arith_string. This inhibits word splitting
(Q_DOUBLE_QUOTED) while discarding double quotes (Q_ARITH), identical to the
quote flags passed while expanding $(( )) and $[ ]. Q_ARRAYSUB reserved for
future use. Fixes problem reported by Stephane Chazelas
<stephane.chazelas@gmail.com>
10/16
-----
subst.c
- parameter_brace_expand_word: if the PF_ASSIGNRHS flag is set and we
are expanding what looks like an array subscripted with @ or *,
make sure the variable we're expanding is actually an array before
we add Q_DOUBLE_QUOTES to the flags. If we don't, things like
scalar[@] will remain quoted. Fixes ubuntu bug 1381567
https://bugs.launchpad.net/ubuntu/+source/bash/+bug/1381567
10/17
-----
{jobs,nojobs}.c
- get_original_tty_job_signals: get original signal dispostions for
SIGTSTP, SIGTTIN, SIGTTOU before we start manipulating them in
make_child
- default_tty_job_signals: make sure we set SIGTSTP, SIGTTIN, or
SIGTTOU to SIG_IGN if they were ignored at shell startup instead of
unconditionally setting them to SIG_DFL. Fixes bug reported by
idallen@idallen.ca
jobs.h
- get_original_tty_job_signals: extern declaration
trap.c
- initialize_traps: add call to get_original_tty_job_signals
+2
View File
@@ -831,6 +831,7 @@ tests/array13.sub f
tests/array14.sub f
tests/array15.sub f
tests/array16.sub f
tests/array17.sub f
tests/array-at-star f
tests/array2.right f
tests/assoc.tests f
@@ -896,6 +897,7 @@ tests/dbg-support3.sub f
tests/dollar-at-star f
tests/dollar-at-star1.sub f
tests/dollar-at-star2.sub f
tests/dollar-at-star3.sub f
tests/dollar-at1.sub f
tests/dollar-at2.sub f
tests/dollar-at3.sub f
+1 -1
View File
@@ -858,7 +858,7 @@ array_expand_index (var, s, len)
exp = (char *)xmalloc (len);
strncpy (exp, s, len - 1);
exp[len - 1] = '\0';
t = expand_arith_string (exp, 0);
t = expand_arith_string (exp, Q_DOUBLE_QUOTES|Q_ARITH|Q_ARRAYSUB); /* XXX - Q_ARRAYSUB for future use */
this_command_name = (char *)NULL;
val = evalexp (t, &expok);
free (t);
+14 -1
View File
@@ -79,6 +79,8 @@ QUIETPS = #set this to -q to shut up dvips
PAPERSIZE = letter # change to a4 for A4-size paper
PSDPI = 600 # could be 300 if you like
DVIPS = dvips -D ${PSDPI} $(QUIETPS) -t ${PAPERSIZE} -o $@ # tricky
# experimental; uses external texi2dvi for now; this needs pdftex to be present
TEXI2PDF = texi2dvi --pdf
TEXINPUTDIR = $(RL_LIBDIR)/doc
SET_TEXINPUTS = TEXINPUTS=.:$(TEXINPUTDIR):$$TEXINPUTS
@@ -146,6 +148,10 @@ BASHREF_FILES = $(srcdir)/bashref.texi $(srcdir)/fdl.texi $(srcdir)/version.texi
${RM} $@
-${DVIPS} $<
#.texi.pdf:
# $(RM) $@
# -${TEXI2PDF} $<
all: ps info dvi text html
nodvi: ps info text html
everything: all pdf
@@ -170,6 +176,11 @@ bashref.dvi: $(BASHREF_FILES) $(HSUSER) $(RLUSER)
bashref.info: $(BASHREF_FILES) $(HSUSER) $(RLUSER)
$(MAKEINFO) --no-split -I$(TEXINPUTDIR) $(srcdir)/bashref.texi
# experimental
bashref.pdf: $(BASHREF_FILES) $(HSUSER) $(RLUSER)
${SET_TEXINPUTS} $(TEXI2PDF) $(srcdir)/bashref.texi || { ${RM} $@ ; exit 1; }
# can also use:
# $(MAKEINFO) --html --no-split -I$(TEXINPUTDIR) $(srcdir)/bashref.texi
bashref.html: $(BASHREF_FILES) $(HSUSER) $(RLUSER)
@@ -193,7 +204,9 @@ article.ps: article.ms
bashref.ps: bashref.dvi
article.pdf: article.ps
bashref.pdf: bashref.dvi
#bashref.pdf: bashref.dvi
# experimental
bashref.pdf: bashref.texi
bash.pdf: bash.ps
rose94.pdf: rose94.ps
+1620 -1619
View File
File diff suppressed because it is too large Load Diff
+2 -2
View File
@@ -1281,7 +1281,7 @@ If the control variable in a \fBfor\fP loop has the nameref attribute,
the list of words can be a list of shell variables, and a name reference
will be established for each word in the list, in turn, when the loop is
executed.
Array variables cannot be given the \fB\nameref\fP attribute.
Array variables cannot be given the \fBnameref\fP attribute.
However, nameref variables can reference array variables and subscripted
array variables.
Namerefs can be unset using the \fB\-n\fP option to the \fBunset\fP builtin.
@@ -5397,7 +5397,7 @@ If set to \fBOn\fP, the history code attempts to place point at the
same location on each history line retrieved with \fBprevious-history\fP
or \fBnext-history\fP.
.TP
.B history\-size (0)
.B history\-size (unset)
Set the maximum number of history entries saved in the history list.
If set to zero, any existing history entries are deleted and no new entries
are saved.
+35 -5
View File
@@ -1942,12 +1942,42 @@ ignore_tty_job_signals ()
set_signal_handler (SIGTTOU, SIG_IGN);
}
/* Reset the tty-generated job control signals to SIG_DFL unless that signal
was ignored at entry to the shell, in which case we need to set it to
SIG_IGN in the child. We can't rely on resetting traps, since the hard
ignored signals can't be trapped. */
void
default_tty_job_signals ()
{
set_signal_handler (SIGTSTP, SIG_DFL);
set_signal_handler (SIGTTIN, SIG_DFL);
set_signal_handler (SIGTTOU, SIG_DFL);
if (signal_is_trapped (SIGTSTP) == 0 && signal_is_hard_ignored (SIGTSTP))
set_signal_handler (SIGTSTP, SIG_IGN);
else
set_signal_handler (SIGTSTP, SIG_DFL);
if (signal_is_trapped (SIGTTIN) == 0 && signal_is_hard_ignored (SIGTTIN))
set_signal_handler (SIGTTIN, SIG_IGN);
else
set_signal_handler (SIGTTIN, SIG_DFL);
if (signal_is_trapped (SIGTTOU) == 0 && signal_is_hard_ignored (SIGTTOU))
set_signal_handler (SIGTTOU, SIG_IGN);
else
set_signal_handler (SIGTTOU, SIG_DFL);
}
/* Called once in a parent process. */
void
get_original_tty_job_signals ()
{
static int fetched = 0;
if (fetched == 0)
{
get_original_signal (SIGTSTP);
get_original_signal (SIGTTIN);
get_original_signal (SIGTTOU);
fetched = 1;
}
}
/* When we end a job abnormally, or if we stop a job, we set the tty to the
@@ -3840,7 +3870,7 @@ initialize_job_control (force)
{
SigHandler *ottin;
ottin = set_signal_handler(SIGTTIN, SIG_DFL);
ottin = set_signal_handler (SIGTTIN, SIG_DFL);
kill (0, SIGTTIN);
set_signal_handler (SIGTTIN, ottin);
continue;
@@ -4007,7 +4037,7 @@ initialize_job_signals ()
old_ttin = set_signal_handler (SIGTTIN, sigstop_sighandler);
old_ttou = set_signal_handler (SIGTTOU, sigstop_sighandler);
}
/* Leave these things alone for non-interactive shells without job
/* Leave disposition unmodified for non-interactive shells without job
control. */
}
+1
View File
@@ -239,6 +239,7 @@ extern void restart_job_control __P((void));
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 get_original_tty_job_signals __P((void));
extern void init_job_stats __P((void));
+1 -1
View File
@@ -449,7 +449,7 @@ If set to \fBOn\fP, the history code attempts to place point at the
same location on each history line retrieved with \fBprevious-history\fP
or \fBnext-history\fP.
.TP
.B history\-size (0)
.B history\-size (unset)
Set the maximum number of history entries saved in the history list.
If set to zero, any existing history entries are deleted and no new entries
are saved.
+29 -3
View File
@@ -584,12 +584,38 @@ void
default_tty_job_signals ()
{
#if defined (SIGTSTP)
set_signal_handler (SIGTSTP, SIG_DFL);
set_signal_handler (SIGTTIN, SIG_DFL);
set_signal_handler (SIGTTOU, SIG_DFL);
if (signal_is_trapped (SIGTSTP) == 0 && signal_is_hard_ignored (SIGTSTP))
set_signal_handler (SIGTSTP, SIG_IGN);
else
set_signal_handler (SIGTSTP, SIG_DFL);
if (signal_is_trapped (SIGTTIN) == 0 && signal_is_hard_ignored (SIGTTIN))
set_signal_handler (SIGTTIN, SIG_IGN);
else
set_signal_handler (SIGTTIN, SIG_DFL);
if (signal_is_trapped (SIGTTOU) == 0 && signal_is_hard_ignored (SIGTTOU))
set_signal_handler (SIGTTOU, SIG_IGN);
else
set_signal_handler (SIGTTOU, SIG_DFL);
#endif
}
/* Called once in a parent process. */
void
get_original_tty_job_signals ()
{
static int fetched = 0;
if (fetched == 0)
{
#if defined (SIGTSTP)
get_original_signal (SIGTSTP);
get_original_signal (SIGTTIN);
get_original_signal (SIGTTOU);
#endif
fetched = 1;
}
}
/* Wait for a single pid (PID) and return its exit status. Called by
the wait builtin. */
int
+237 -237
View File
File diff suppressed because it is too large Load Diff
+20 -10
View File
@@ -3214,6 +3214,8 @@ expand_arith_string (string, quoted)
ret = (char *)NULL;
FREE (td.word);
}
else if (saw_quote && (quoted & Q_ARITH))
ret = string_quote_removal (string, quoted);
else if (saw_quote && ((quoted & (Q_HERE_DOCUMENT|Q_DOUBLE_QUOTES)) == 0))
ret = string_quote_removal (string, quoted);
else
@@ -5824,13 +5826,19 @@ parameter_brace_expand_word (name, var_is_special, quoted, pflags, indp)
expand_arrayref:
/* XXX - does this leak if name[@] or name[*]? */
if (pflags & PF_ASSIGNRHS)
{
temp = array_variable_name (name, &tt, (int *)0);
if (ALL_ELEMENT_SUB (tt[0]) && tt[1] == ']')
temp = array_value (name, quoted|Q_DOUBLE_QUOTES, 0, &atype, &ind);
{
var = array_variable_part (name, &tt, (int *)0);
if (ALL_ELEMENT_SUB (tt[0]) && tt[1] == ']')
{
/* Only treat as double quoted if array variable */
if (var && (array_p (var) || assoc_p (var)))
temp = array_value (name, quoted|Q_DOUBLE_QUOTES, 0, &atype, &ind);
else
temp = array_value (name, quoted, 0, &atype, &ind);
}
else
temp = array_value (name, quoted, 0, &atype, &ind);
}
}
else
temp = array_value (name, quoted, 0, &atype, &ind);
if (atype == 0 && temp)
@@ -8008,7 +8016,7 @@ param_expand (string, sindex, quoted, expanded_something,
}
/* Expand variables found inside the expression. */
temp1 = expand_arith_string (temp2, Q_DOUBLE_QUOTES);
temp1 = expand_arith_string (temp2, Q_DOUBLE_QUOTES|Q_ARITH);
free (temp2);
arithsub:
@@ -8062,7 +8070,7 @@ comsub:
}
/* Do initial variable expansion. */
temp1 = expand_arith_string (temp, Q_DOUBLE_QUOTES);
temp1 = expand_arith_string (temp, Q_DOUBLE_QUOTES|Q_ARITH);
goto arithsub;
@@ -8410,10 +8418,12 @@ add_string:
case '~':
/* If the word isn't supposed to be tilde expanded, or we're not
at the start of a word or after an unquoted : or = in an
assignment statement, we don't do tilde expansion. */
assignment statement, we don't do tilde expansion. If we don't want
tilde expansion when expanding words to be passed to the arithmetic
evaluator, remove the check for Q_ARITH. */
if ((word->flags & (W_NOTILDE|W_DQUOTE)) ||
(sindex > 0 && ((word->flags & W_ITILDE) == 0)) ||
(quoted & (Q_DOUBLE_QUOTES|Q_HERE_DOCUMENT)))
((quoted & (Q_DOUBLE_QUOTES|Q_HERE_DOCUMENT)) && ((quoted & Q_ARITH) == 0)))
{
word->flags &= ~W_ITILDE;
if (isexp == 0 && (word->flags & (W_NOSPLIT|W_NOSPLIT2)) == 0 && isifs (c) && (quoted & (Q_DOUBLE_QUOTES|Q_HERE_DOCUMENT)) == 0)
@@ -8597,7 +8607,7 @@ add_twochars:
break;
case '"':
if ((quoted & (Q_DOUBLE_QUOTES|Q_HERE_DOCUMENT)))
if ((quoted & (Q_DOUBLE_QUOTES|Q_HERE_DOCUMENT)) && ((quoted & Q_ARITH) == 0))
goto add_character;
t_index = ++sindex;
+10 -8
View File
@@ -32,14 +32,16 @@
expanding a pattern ${var%#[#%]pattern} in an expansion surrounded
by double quotes. Q_DOLBRACE means we are expanding a ${...} word, so
backslashes should also escape { and } and be removed. */
#define Q_DOUBLE_QUOTES 0x01
#define Q_HERE_DOCUMENT 0x02
#define Q_KEEP_BACKSLASH 0x04
#define Q_PATQUOTE 0x08
#define Q_QUOTED 0x10
#define Q_ADDEDQUOTES 0x20
#define Q_QUOTEDNULL 0x40
#define Q_DOLBRACE 0x80
#define Q_DOUBLE_QUOTES 0x001
#define Q_HERE_DOCUMENT 0x002
#define Q_KEEP_BACKSLASH 0x004
#define Q_PATQUOTE 0x008
#define Q_QUOTED 0x010
#define Q_ADDEDQUOTES 0x020
#define Q_QUOTEDNULL 0x040
#define Q_DOLBRACE 0x080
#define Q_ARITH 0x100 /* expanding string for arithmetic evaluation */
#define Q_ARRAYSUB 0x200 /* expanding indexed array subscript */
/* Flag values controlling how assignment statements are treated. */
#define ASS_APPEND 0x0001
+23
View File
@@ -388,3 +388,26 @@ bar: array with element zero unset: ok
bar: element zero: ok
qux: unset array: ok
qux: unset array element 0: ok
2
2
2
2
0
0
1
2
0
0
3
3
0
0
zero
zero
one
one
one
one
two
two
./array17.sub: line 76: ~ : syntax error: operand expected (error token is "~ ")
+2
View File
@@ -400,3 +400,5 @@ ${THIS_SH} ./array14.sub
${THIS_SH} ./array15.sub
${THIS_SH} ./array16.sub
${THIS_SH} ./array17.sub
+78
View File
@@ -0,0 +1,78 @@
# this shows the expansions an array subscript undergoes before being run
# through the arithmetic evaluator
b=(0 1 2 3)
# array subscripts undergo variable expansion
a=2
echo ${b[$a]}
# array subscripts undergo command substitution
echo ${b[$(echo 2)]}
c='1+1'
d='1-+1'
# array subscripts are expanded and the expanded value is treated as an
# expression
echo ${b[$c]}
echo ${b[c]}
echo ${b[$d]}
echo ${b[d]}
# array subscripts undergo parameter expansion
set -- 1 2 3
echo ${b[$1]}
# array subscripts undergo tilde expansion
HOME=2
echo ${b[~]}
# array subscripts undergo word splitting -- bug in bash versions through 4.3
x='b[$d]'
IFS=-
echo $((x))
IFS=$' \t\n'
set -- 1 + 2
x='d'
IFS=-
echo $((x))
IFS=$' \t\n'
# start of quoting tests; make sure that subscript is treated as double
# quoted (inhibits word splitting) but that double quotes are silently
# discarded through quote removal
echo $(( $@ ))
echo "$(( $@ ))"
echo $(( "$x" ))
echo $(( "x" ))
unset a foo bar
a=(zero one two three four five six seven eight nine ten)
echo ${a[0]}
echo ${a["0"]}
foo=1
echo ${a[$foo]}
echo ${a["$foo"]}
echo ${a[foo]}
echo ${a["foo"]}
bar=2
echo ${a[" $bar "]}
echo ${a[" bar "]}
# tilde expansion is performed by array subscript expansion but not by posix
# style arithmetic expansion
HOME=2
echo $(( ~ ))
+2
View File
@@ -215,6 +215,8 @@ ${THIS_SH} ./dollar-at-star1.sub
# splitting
${THIS_SH} ./dollar-at-star2.sub
${THIS_SH} ./dollar-at-star3.sub
# tests for special expansion of "$*" and "${array[*]}" when used with other
# expansions -- bugs through bash-2.05b
${THIS_SH} ./dollar-star1.sub
+17
View File
@@ -0,0 +1,17 @@
unset f ; f=abcd
first_char=${f[@]:0:1}
recho $first_char
first_char="${f[@]:0:1}"
recho $first_char
unset f;
f=( one two three )
first_word=${f[@]:0:1}
recho $first_word
set -- abc def ghi
printf '<%s> ' "123 $@ 456"; echo
printf '<%s> ' "123 $@\ 456"; echo
+5
View File
@@ -156,6 +156,11 @@ ok at 6
ok at 7
ok at 8
ok at 9
argv[1] = <a>
argv[1] = <a>
argv[1] = <one>
<123 abc> <def> <ghi 456>
<123 abc> <def> <ghi\ 456>
xa|xb|xc
xa|xb|xc
a|b|c
+2
View File
@@ -186,6 +186,8 @@ initialize_traps ()
GETORIGSIG (SIGTERM);
sigmodes[SIGTERM] |= SIG_SPECIAL;
}
get_original_tty_job_signals ();
}
#ifdef DEBUG