Subject: bug#21416: "--" syntax for ignoring flags doesn't seem to work right with GNU /bin/echo

From: Eric Blake <[email-masked]>
Date: Fri, 4 Sep 2015 16:42:48 -0600

On 09/04/2015 04:34 PM, Eric Blake wrote:
> [As it is, bash has a bug:
> $ (shopt -s xpg_echo; echo -e)
> 
> should output '-e', but currently outputs nothing.  Also, bash does not
> quite treat POSIXLY_CORRECT=1 (also spelled 'set -o posix') as the
> override to turn on full POSIX compliance, as it leaves xpg_echo as a
> separate knob; ideally, turning on posix compliance in bash should turn
> on xpg_echo - but enough people are used to the old behavior that it was
> decided to keep the knobs separate]

Maybe I spoke too soon. It looks like bash needs BOTH xpg_echo and posix
mode at the same time, either one in isolation is not enough:

$ for opt in '' 'shopt -s xpg_echo' 'set -o posix' \
     'shopt -s xpg_echo; set -o posix'; do
    bash -c "echo 'trying $opt'; ${opt:-:}; echo -e"
  done
trying

trying shopt -s xpg_echo

trying set -o posix

trying shopt -s xpg_echo; set -o posix
-e

$

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org