Bash 4.4 doesn't compile on GCC 5.2(easy steps to reproduce)

2016-09-16 Thread Lilian Moraru
Hello,

I tried to compile Bash 4.4 in Habitat(habitat.sh):
https://github.com/habitat-sh/core-plans/tree/master/bash and it fails to
compile with the following messages:
```
gcc  -DPROGRAM='"bash"' -DCONF_HOSTTYPE='"x86_64"'
-DCONF_OSTYPE='"linux-gnu"' -DCONF_MACHTYPE='"x86_64-unknown-linux-gnu"'
-DCONF_VENDOR='"unknown"'
-DLOCALEDIR='"/hab/pkgs/lilian/bash/4.4.0/20160916115954/share/locale"'
-DPACKAGE='"bash"' -DSHELL -DHAVE_CONFIG_H   -I.
-I/hab/pkgs/core/readline/6.3.8/20160729192706/include -I. -I./include
-I./lib  -I/hab/pkgs/core/glibc/2.22/20160612063629/include
-I/hab/pkgs/core/ncurses/6.0/20160612075116/include
-I/hab/pkgs/core/readline/6.3.8/20160729192706/include
-I/hab/pkgs/core/make/4.2.1/20160729193703/include
-I/hab/pkgs/core/gcc/5.2.0/20160612064854/include
-I/hab/pkgs/core/glibc/2.22/20160612063629/include
-I/hab/pkgs/core/ncurses/6.0/20160612075116/include
-I/hab/pkgs/core/readline/6.3.8/20160729192706/include
-I/hab/pkgs/core/make/4.2.1/20160729193703/include
-I/hab/pkgs/core/gcc/5.2.0/20160612064854/include -Wno-parentheses
-Wno-format-security -c bashhist.c
bashhist.c: In function 'load_history':
bashhist.c:324:31: error: 'history_lines_read_from_file' undeclared (first
use in this function)
   history_lines_in_file = history_lines_read_from_file;
   ^
bashhist.c:324:31: note: each undeclared identifier is reported only once
for each function it appears in
bashhist.c: In function 'maybe_save_shell_history':
bashhist.c:474:32: error: 'history_lines_written_to_file' undeclared (first
use in this function)
history_lines_in_file = history_lines_written_to_file;
^
make: *** [Makefile:99: bashhist.o] Error 1
```

The issue is very easy to reproduce if you "install"(it's a static binary)
Habitat, because it builds in an isolated environment.
I prepared the change in a fork(Bash 4.3 compiles ok, only 4.4 does not
compile).
In order to reproduce the issue, you can follow these steps:

1. Download the latest version of Habitat for Linux:
https://www.habitat.sh/docs/get-habitat/

2. tar xf hab-0.9.1-20160901204602-x86_64-linux.tar.gz && sudo mv
hab-0.9.1-20160901204602-x86_64-linux/hab /usr/local/bin/

3. alias hab="sudo hab"

4. "hab setup" is necessary to generate a key, later used to enter the hab
studio, to build "bash":
$ hab setup

5. You most probably already have Git, but to fill the steps:
$ hab install core/git && hab pkg binlink --dest /usr/local/bin core/git git

6. git clone https://github.com/lilianmoraru/core-plans.git && cd core-plans

7. hab studio enter

8. cd bash && export DO_CHECK=true

9. build


Re: Command substitution with null bytes generates warning

2016-09-16 Thread Greg Wooledge
On Thu, Sep 15, 2016 at 10:51:22PM -0700, Eric Pruitt wrote:
> Fix:
>   Is this even an intentional change? I looked at some of the other
>   internal_warning invocations, and they were commented out using "#if 0 
> ...
>   #endif."

In 4.4-beta2, I see them in subst.c and parse.y and y.tab.c.  In subst.c
they are inside an "#if 1" block.  In the other two, they are inside
"#if 0".

I do not understand the discrepancy, but I would assume Chet made the
change intentionally.  It seems unlikely to be something one would do
accidentally.



Bash-4.4 Release available

2016-09-16 Thread Chet Ramey
Introduction


The first public release of bash-4.4 is now available with the URLs

ftp://ftp.cwru.edu/pub/bash/bash-4.4.tar.gz
ftp://ftp.gnu.org/pub/gnu/bash/bash-4.4.tar.gz

and from the GNU git repository and the usual GNU mirror sites.

Bash is the GNU Project's Bourne Again SHell, a complete
implementation of the POSIX shell spec, but also with interactive
command line editing, job control on architectures that support it,
csh-like features such as history substitution and brace expansion,
and a slew of other features.  For more information on the features of
Bash that are new to this type of shell, see the file
`doc/bashref.texi'.  There is also a large Unix-style man page.  The
man page is the definitive description of the shell's features. 

This tar file includes the formatted documentation (postscript, dvi, html,
and nroffed versions of the manual pages). 

Please use `bashbug' to report bugs with this version.  It is built
and installed at the same time as bash.

Installation


Please read the README file first.

Installation instructions are provided in the INSTALL file.

New Features


This is the fourth revision to the fourth major release of bash.

Read the file NEWS in the bash-4.4 distribution for a complete description
of the new features.  A copy of the relevant portions is included below. 

This release fixes many outstanding bugs in bash-4.3 and introduces several
new features.  The most significant bug fixes are the remaining changes to
reworking of signal handling to avoid running signal and trap handlers in a
signal handler context.  There are also several changes dealing with variables
that have been given attributes but not values, which means they are
technically unset.  The nameref variable implementation was overhauled
and cleaned up considerably, with as little disruption to backwards
compatibility as possible.

All of the released patches for the shellshock vulnerability, and several
other related changes, are included in bash-4.4.

The most notable new features are mapfile's ability to use an arbitrary
record delimiter; a --help option available for nearly all builtins; a
new family of ${parameter@spec} expansions that transform the value of
`parameter'; the `local' builtin's ability to save and restore the state
of the single-letter shell option flags around function calls; a new
EXECIGNORE variable, which adds the ability to specify names that should
be ignored when searching for commands; and the beginning of an SDK for
loadable builtins, which consists of a set of headers and a Makefile
fragment that can be included in projects wishing to build their own
loadable builtins, augmented by support for a BASH_LOADABLES_PATH variable
that defines a search path for builtins loaded with `enable -f'.  The existing
loadable builtin examples are now installed by default with `make install'.

There are a few incompatible changes between bash-4.3 and bash-4.4.  Bash
now retains the exit status only of asynchronous jobs, as opposed to all
jobs.  This means that it is not possible to use `wait' to retrieve the
status of a previously-completed synchronous command.  Bash no longer
attempts to perform compound assignment if a variable expansion on the
right-hand side of an assignment statement to `declare' or `local' has the
form of a compound assignment.  There are other changes to compound array
assignments used as arguments to the `declare' and `local' builtins, but
those should be backwards compatible, albeit with warning messages about
deprecated constructs.  Read the descriptions of the various compatibility
options in COMPAT or the man page for more details. 

Bash can be linked against an already-installed Readline library rather
than the private version in lib/readline if desired.  Only readline-7.0 and
later versions are able to provide all of the symbols that bash-4.4 requires;
earlier versions of the Readline library will not work correctly. 

A complete list of changes between bash-4.3 and bash-4.4 is available in
the file CHANGES; the complete list is too large to include in this
message. 

Readline


Also available is a new release of the standalone Readline library,
version 7.0, with its own configuration scripts and Makefiles. 
It can be retrieved with the URLs

ftp://ftp.cwru.edu/pub/bash/readline-7.0.tar.gz
ftp://ftp.gnu.org/pub/gnu/readline/readline-7.0.tar.gz

and from the GNU git repository and the usual GNU mirror sites.

The formatted Readline documentation is included in the readline
distribution tar file.

A separate announcement listing the changes in Readline is being
distributed.

As always, thanks for your help.

Chet

+== NEWS ==+
This is a terse description of the new features added to bash-4.4 since
the release of bash-4.3.  As always, the manual page (doc/bash.1) is
the place to look for complete descriptions.

1.  New Features in Bash

a.  There is now a settable configuration #define that will 

Readline-7.0 Release available

2016-09-16 Thread Chet Ramey
The first public release of the GNU Readline library, version 7.0,
is now available for FTP with the URLs

ftp://ftp.cwru.edu/pub/bash/readline-7.0.tar.gz
ftp://ftp.gnu.org/pub/gnu/readline/readline-7.0.tar.gz

and from the GNU git repository and the usual GNU mirror sites.

GNU Readline is a library which provides programs with an input
facility including command-line editing and history.  Editing
commands similar to both emacs and vi are included.  The GNU
History library, which provides facilities for managing a list of
previously-typed command lines and an interactive command line
recall facility similar to that provided by csh, is also present.
The history library is built as part of the readline as well as
separately.

This distribution is essentially a standalone version of the
readline library that appears in Bash-4.4 together with
an `autoconf' framework.  The documentation has been updated and
is current.  Postscript, DVI, and Info versions of the Readline
and History manuals are included.  A list of changes in this
release is appended to this announcement.

This release accompanies the simultaneous release of bash-4.4.
There are more improvements in the programming interface and new
user-visible variables and bindable commands.

The signal handling has been reworked so that it will not run code in
a signal handler context, and there are additional signal and event
handling hooks to improve application responsiveness.  The history
file manipulation functions now do a better job of restoring the old
history file on write errors.  There is a new bindable variable to
enable a `bracketed paste' mode, which is available in new terminal
emulators and indicates to programs when input is coming from a paste
instead of the keyboard, so the input can be handled as one big chunk
of text to insert.  Similarly, the text insert functions attempt to
batch-insert all pending typeahead characters that map to
`self-insert' as long as the input is coming from a terminal.  The
editing mode indicators are now user-settable strings that can contain
non-printing characters.  It is now possible to have the common prefix
of a set of completions displayed in a different color when listing
possible completions. 

Please send readline bug reports to bug-readl...@gnu.org.

As always, thanks for your help.

Chet

+== CHANGES ==+
This document details the changes between this version, readline-7.0, and the
previous version, readline-6.3.

1.  Changes to Readline

a.  A bug that caused vi-mode `.' to be unable to redo `c', `d', and `y'
commands with modifiers was fixed.

b.  Fixed a bug that caused callback mode to dump core when reading a
multiple-key sequence (e.g., arrow keys).

c.  Fixed a bug that caused the redisplay code to erase some of the line when
using horizontal scrolling with incremental search.

d.  Readline's input handler now performs signal processing if read(2) is
interrupted by SIGALRM or SIGVTALRM.

e.  Fixed a problem with revert-all-at-newline freeing freed memory.

f.  Clarified the documentation for the history_quotes_inhibit_expansion
variable to note that it inhibits scanning for the history comment
character and that it only affects double-quoted strings.

g.  Fixed an off-by-one error in the prompt printed when performing searches.

h.  Use pselect(2), if available, to wait for input before calling read(2), so
a SIGWINCH can interrupt it, since it doesn't interrupt read(2).

i.  Some memory leaks caused by signals interrupting filename completion have
been fixed.

j.  Reading EOF twice on a non-empty line causes EOF to be returned, rather
than the partial line.  This can cause partial lines to be executed on
SIGHUP, for example.

k.  Fixed a bug concerning deleting multibyte characters from the search
string while performing an incremental search.

l.  Fixed a bug with tilde expanding directory names in filename completion.

m.  Fixed a bug that did not allow binding sequences beginning with a `\'.

n.  Fixed a redisplay bug involving incorrect line wrapping when the prompt
contains a multibyte character in the last screen column.

o.  Fixed a bug that caused history expansion to disregard characters that are
documented to delimit a history event specifier without requiring `:'.

p.  Fixed a bug that could cause reading past the end of a string when reading
the value when binding the set of isearch terminators.

q.  Fixed a bug that caused readline commands that depend on knowing which  
key invoked them to misbehave when dispatching key sequences that are
prefixes of other key bindings. 

r.  Paren matching now works in vi insert mode.

s.  Colored completion prefixes are now displayed using a different color, less
likely to collide with files.

t.  Fixed a bug that caused vi-mode character search to misbehave when
running in callback mode.

u.  Fixed a bug that caused output to be delayed when input is coming f

Re: Bash 4.4 doesn't compile on GCC 5.2(easy steps to reproduce)

2016-09-16 Thread Andreas Schwab
On Sep 16 2016, Lilian Moraru  wrote:

> Hello,
>
> I tried to compile Bash 4.4 in Habitat(habitat.sh):
> https://github.com/habitat-sh/core-plans/tree/master/bash and it fails to
> compile with the following messages:
> ```
> gcc  -DPROGRAM='"bash"' -DCONF_HOSTTYPE='"x86_64"'
> -DCONF_OSTYPE='"linux-gnu"' -DCONF_MACHTYPE='"x86_64-unknown-linux-gnu"'
> -DCONF_VENDOR='"unknown"'
> -DLOCALEDIR='"/hab/pkgs/lilian/bash/4.4.0/20160916115954/share/locale"'
> -DPACKAGE='"bash"' -DSHELL -DHAVE_CONFIG_H   -I.
> -I/hab/pkgs/core/readline/6.3.8/20160729192706/include -I. -I./include

Your readline doesn't match.  You need to use the bundled library.

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."



[minor] [[ "\\" =~ [^]"."] ]] returns false

2016-09-16 Thread Stephane Chazelas
That's a special case of the

[[ "\\" =~ ["."] ]]

returning true (because bash called regcomp("[\\.]") instead of
regcomp("[.]") I had reported some time ago and was then fixed.

Here. It's similar:

$ bash -c '[[ "\\" =~ [^]"."] ]]' || echo unexpected
unexpected

$ ltrace -e regcomp bash -c '[[ "\\" =~ [^]"."] ]]'
bash->regcomp(0x7ffc146e78c0, "[^]\\.]", 1)  = 0

I suspect bash thinks the first "]" closes the bracket
expression and thus assumes the "." is outside them so needs to
be escaped for the RE engine as it's quoted in the bash RE.

-- 
Stephane



Behavior of ${var/*/text} has changed

2016-09-16 Thread Eric Pruitt
Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64' 
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='x86_64-unknown-linux-gnu' 
-DCONF_VENDOR='unknown' -DLOCALEDIR='/usr/local/share/locale' -DPACKAGE='bash' 
-DSHELL -DHAVE_CONFIG_H   -I.  -I. -I./include -I./lib   -g -O2 
-Wno-parentheses -Wno-format-security
uname output: Linux sinister 3.16.0-4-amd64 #1 SMP Debian 3.16.36-1+deb8u1 
(2016-09-03) x86_64 GNU/Linux
Machine Type: x86_64-unknown-linux-gnu

Bash Version: 4.4
Patch Level: 0
Release Status: release

Description:
In Bash 4.3, "${var/*/text}" would generate "" if var was a zero-length
string and "text" if it contained at least one character. In Bash 4.4, 
this
is no longer the case. I'm not sure if this is necessarily a bug, but I 
was
unable to find this change in behavior in the change log or man page.

Repeat-By:
Bash 4.3:
ericpruitt@sinister:~$ echo ${VAR/*/VAR was not empty}
VAR was not empty
ericpruitt@sinister:~$ VAR=
ericpruitt@sinister:~$ echo ${VAR/*/VAR was not empty}

ericpruitt@sinister:~$

Bash 4.4:
ericpruitt@sinister:~$ VAR=NotEmpty
ericpruitt@sinister:~$ echo ${VAR/*/VAR was not empty}
VAR was not empty
ericpruitt@sinister:~$ VAR=
ericpruitt@sinister:~$ echo ${VAR/*/VAR was not empty}
VAR was not empty
ericpruitt@sinister:~$

Fix:
As a work-around, I have changed the expressions I'm using from
${VAR/*/...} to ${VAR/?*/...}. Since it is not clear to me if this is
actually a bug, I'm not sure what that fix should be. Maybe there
should be a new "compat..." option.



Re: Behavior of ${var/*/text} has changed

2016-09-16 Thread Greg Wooledge
On Fri, Sep 16, 2016 at 12:06:53PM -0700, Eric Pruitt wrote:
>   Bash 4.3:
>   ericpruitt@sinister:~$ VAR=
>   ericpruitt@sinister:~$ echo ${VAR/*/VAR was not empty}
>   

>   Bash 4.4:
>   ericpruitt@sinister:~$ VAR=
>   ericpruitt@sinister:~$ echo ${VAR/*/VAR was not empty}
>   VAR was not empty

Off hand I'd say the bash 4.4 behavior is correct.  * matches 0 or
more characters, so it should match an empty or undefined variable.

> Fix:
>   As a work-around, I have changed the expressions I'm using from
>   ${VAR/*/...} to ${VAR/?*/...}.

That, or ${VAR:+not empty} which is how I suggest testing for variable
set-and-not-empty-ness.

http://mywiki.wooledge.org/BashFAQ/083



Re: Behavior of ${var/*/text} has changed

2016-09-16 Thread Eric Pruitt
On Fri, Sep 16, 2016 at 03:22:29PM -0400, Greg Wooledge wrote:
> Off hand I'd say the bash 4.4 behavior is correct.  * matches 0 or
> more characters, so it should match an empty or undefined variable.

Yes, I agree that the Bash 4.4 behavior is more reasonable, but I think
the change at least needs to be documented (assuming I didn't miss it).

> > Fix:
> > As a work-around, I have changed the expressions I'm using from
> > ${VAR/*/...} to ${VAR/?*/...}.
>
> That, or ${VAR:+not empty} which is how I suggest testing for variable
> set-and-not-empty-ness.

I'm aware of that construct, but that doesn't do what I want unless I'm
missing something; I don't want to change the value of the variable.
Here's an example from my prompt command:

function prompt-command()
{
# [...]

local jobs="$(jobs)"

# [...]

PS1="${SSH_TTY/?*/\\u@\\h:}\\W${jobs/?*/ [\\j]}\\$ "

# [...]
}

In this example, I want to show the username and hostname if SSH_TTY is
set and not empty, but I do not want to modify its value. I am also
showing the number of jobs in brackets, but I only want to do that if
there are some jobs in the background.

Eric



Re: Behavior of ${var/*/text} has changed

2016-09-16 Thread Greg Wooledge
On Fri, Sep 16, 2016 at 12:30:59PM -0700, Eric Pruitt wrote:
> PS1="${SSH_TTY/?*/\\u@\\h:}\\W${jobs/?*/ [\\j]}\\$ "
> 
> In this example, I want to show the username and hostname if SSH_TTY is
> set and not empty, but I do not want to modify its value. I am also
> showing the number of jobs in brackets, but I only want to do that if
> there are some jobs in the background.

You're confusing :+ with :=

imadev:~$ echo "$BASH_VERSION"
4.4.0(1)-release
imadev:~$ unset undefined; defined=yes; empty=  
imadev:~$ echo "<${undefined:+a}> <${defined:+b}> <${empty:+c}>"
<>  <>
imadev:~$ echo "<${undefined+a}> <${defined+b}> <${empty+c}>"
<>  
imadev:~$ declare -p undefined defined empty
bash: declare: undefined: not found
declare -- defined="yes"
declare -- empty=""



Re: Behavior of ${var/*/text} has changed

2016-09-16 Thread Eric Pruitt
On Fri, Sep 16, 2016 at 12:30:59PM -0700, Eric Pruitt wrote:
> > That, or ${VAR:+not empty} which is how I suggest testing for variable
> > set-and-not-empty-ness.
>
> I'm aware of that construct, but that doesn't do what I want unless I'm
> missing something; I don't want to change the value of the variable.

Actually, I misunderstood what you wrote when I skimmed your message the
first time. However, that construct still won't work because if a
variable is defined, it will still choose "not empty:"

ericpruitt@sinister:~$ X=
ericpruitt@sinister:~$ echo ${X+Not empty}
Not empty
ericpruitt@sinister:~$ X=XXX
ericpruitt@sinister:~$ echo ${X+Not empty}
Not empty

Eric



Re: Behavior of ${var/*/text} has changed

2016-09-16 Thread Greg Wooledge
On Fri, Sep 16, 2016 at 12:38:20PM -0700, Eric Pruitt wrote:
> first time. However, that construct still won't work because if a
> variable is defined, it will still choose "not empty:"
> 
> ericpruitt@sinister:~$ X=
> ericpruitt@sinister:~$ echo ${X+Not empty}
> Not empty

Then you want :+ instead of +

Note that I had :+ (not +) in my original email.

imadev:~$ X=
imadev:~$ echo "${X+Not empty}"
Not empty
imadev:~$ echo "${X:+Not empty}"

imadev:~$ 



Re: Behavior of ${var/*/text} has changed

2016-09-16 Thread Eric Pruitt
On Fri, Sep 16, 2016 at 03:45:39PM -0400, Greg Wooledge wrote:
> On Fri, Sep 16, 2016 at 12:38:20PM -0700, Eric Pruitt wrote:
> > first time. However, that construct still won't work because if a
> > variable is defined, it will still choose "not empty:"
> >
> > ericpruitt@sinister:~$ X=
> > ericpruitt@sinister:~$ echo ${X+Not empty}
> > Not empty
>
> Then you want :+ instead of +
>
> Note that I had :+ (not +) in my original email.
>
> imadev:~$ X=
> imadev:~$ echo "${X+Not empty}"
> Not empty
> imadev:~$ echo "${X:+Not empty}"
>
> imadev:~$

Right you are; thanks.

Eric



build failure with enable-static-link

2016-09-16 Thread Ben
Hello,

bash-4.4 doesn't build with --enable-static-link. Buidling with an
additional --without-bash-malloc makes it work.

/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../lib64/libc.a(malloc.o):
In function `free':
(.text+0x5f20): multiple definition of `free'
./lib/malloc/libmalloc.a(malloc.o):/home/benoit/bash/bash-4.4/lib/malloc/malloc.c:1273:
first defined here
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../lib64/libc.a(malloc.o):
In function `malloc':
(.text+0x5160): multiple definition of `malloc'
./lib/malloc/libmalloc.a(malloc.o):/home/benoit/bash/bash-4.4/lib/malloc/malloc.c:1258:
first defined here
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../lib64/libc.a(malloc.o):
In function `realloc':
(.text+0x6400): multiple definition of `realloc'
./lib/malloc/libmalloc.a(malloc.o):/home/benoit/bash/bash-4.4/lib/malloc/malloc.c:1266:
first defined here
collect2: ld returned 1 exit status
make: *** [bash] Error 1

-- 
Benoît Dejean



PS0 issue with escape sequence

2016-09-16 Thread Ben
Hello,

using bash-4.4, setting PS0 to '\[\033[1;36m\]started at
\t\[\033[0m\]\n' makes it output PS0 with a non-printable \x01\x02
prefix and suffix.

  01 02 73 74 61 72 74 65  64 20 61 74 20 30 33 3a  |..started at 03:|
0010  31 38 3a 30 37 01 02 0a   |18:07...|

-- 
Benoît Dejean