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 



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 



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-07 Thread Greg Wooledge
On Mon, Aug 07, 2017 at 05:32:21PM +0300, Reto wrote:
> 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
> 
> 
> 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?

I can't reproduce this on Debian 9:

wooledg:~$ (exec -a /bin/sh bash)
sh-4.4$ command() { echo hi; }
sh-4.4$ command
hi
sh-4.4$ echo "$BASH_VERSION"
4.4.12(1)-release



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

2017-08-07 Thread Chet Ramey
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.

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRUc...@case.eduhttp://cnswww.cns.cwru.edu/~chet/