bash 4.4 changed behavior wrt to builtin 'command'

2017-08-07 Thread Reto

Hi,

Not sure if it's a bug or intended behavior, but in bash 4.4 the 
behavior changed with respect to builtin command 'command', called with 
/bin/sh.


While in bash 4.3 the following works:

# /bin/sh --version
GNU bash, version 4.3.43(1)-release (x86_64-redhat-linux-gnu)
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later 
<http://gnu.org/licenses/gpl.html>


This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
# /bin/sh -c 'command(){ echo FOO;}; command'
FOO
#


It does not work anymore in bash 4.4:

# /bin/sh --version
GNU bash, version 4.4.12(1)-release (x86_64-redhat-linux-gnu)
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later 
<http://gnu.org/licenses/gpl.html>


This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
# /bin/sh -c 'command(){ echo FOO;}; command'
/bin/sh: `command': is a special builtin
#

AFIK 'command' is no built in command in bourne shell,
so I think it could be expected that if bash is called with /bin/sh 
'command' can be used as function name?


trying with other builtin commands in 4.3 and 4.4:

- 'shift' and 'exec' are bourne shell builtins (so it's expected they 
fail in /bin/sh case, not sure why it works in bash case?)


- 'bg' and 'command' are just bash builtins (so expected it works in 
/bin/sh case (it does for 'bg' but not for 'command'?), not sure why it 
works in bash case?)


bash4.3.43# /bin/sh -c 'shift(){ echo FOO;}; shift'
/bin/sh: `shift': is a special builtin
bash4.3.43# /bin/bash -c 'shift(){ echo FOO;}; shift'
FOO
bash4.3.43# /bin/sh -c 'bg(){ echo FOO;}; bg'
FOO
bash4.3.43# /bin/bash -c 'bg(){ echo FOO;}; bg'
FOO
bash4.3.43# /bin/sh -c 'exec(){ echo FOO;}; exec'
/bin/sh: `exec': is a special builtin
bash4.3.43# /bin/bash -c 'exec(){ echo FOO;}; exec'
FOO
bash4.3.43#  /bin/sh -c 'command(){ echo FOO;}; command'
FOO
bash4.3.43#  /bin/bash -c 'command(){ echo FOO;}; command'
FOO
bash4.3.43#


bash4.4.12# /bin/sh -c 'shift(){ echo FOO;}; shift'
/bin/sh: `shift': is a special builtin
bash4.4.12# /bin/bash -c 'shift(){ echo FOO;}; shift'
FOO
bash4.4.12# /bin/sh -c 'bg(){ echo FOO;}; bg'
FOO
bash4.4.12# /bin/bash -c 'bg(){ echo FOO;}; bg'
FOO
bash4.4.12# /bin/sh -c 'exec(){ echo FOO;}; exec'
/bin/sh: `exec': is a special builtin
bash4.4.12# /bin/bash -c 'exec(){ echo FOO;}; exec'
FOO
bash4.4.12# /bin/sh -c 'command(){ echo FOO;}; command'
/bin/sh: `command': is a special builtin
bash4.4.12# /bin/bash -c 'command(){ echo FOO;}; command'
FOO
bash4.4.12#


regards
Reto



Re: bash 4.4 changed behavior wrt to builtin 'command'

2017-08-09 Thread Reto

Hi,

On 07.08.2017 21:38, Chet Ramey wrote:

On 8/7/17 10:32 AM, Reto wrote:

Hi,

Not sure if it's a bug or intended behavior, but in bash 4.4 the behavior
changed with respect to builtin command 'command', called with /bin/sh.


When in Posix mode, bash doesn't allow functions to be defined with the
same name as a special builtin. It seems like RedHat added `command' to
the list of special builtins in their custom build of bash-4.4. Open a
ticket if they're your vendor.



OK, thanks for the explanation.

For reference I opened the following bug:
https://bugzilla.redhat.com/show_bug.cgi?id=1479220

best regards
Reto