String replacement drops leading '-e' if replacing char is a space

2023-08-13 Thread pphick via Bug reports for the GNU Bourne Again SHell
Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -g -O2 -flto=auto -ffat-lto-objects -flto=auto 
-ffat-lto-objects -fstack-protector-strong -Wformat -Werror=format-s>
uname output: Linux saturn 6.2.6-76060206-generic 
#202303130630~1689015125~22.04~ab2190e~dev-Ubuntu SMP PREEMPT_DY x86_64 x86_64 
x86_64>
Machine Type: x86_64-pc-linux-gnu

Bash Version: 5.1
Patch Level: 16
Release Status: release

Description:

If a string starts with '-e' the replacement operators ${x//,/ } and ${x/, /} 
drop the '-e'.
The behaviour seems to be very specific: the string must start with '-e' and 
the replacing character has to be a space.

Repeat-By:

x='-e,b,c'
echo ${x//,/ }
b c
echo ${x/,/ }
b,c

P. Paul Hick
Email: pph...@protonmail.com

Re: String replacement drops leading '-e' if replacing char is a space

2023-08-13 Thread Eduardo Bustamante
>
> Description:
>
> If a string starts with '-e' the replacement operators ${x//,/ } and ${x/,
> /} drop the '-e'.
> The behaviour seems to be very specific: the string must start with '-e'
> and the replacing character has to be a space.
>
> Repeat-By:
>
> x='-e,b,c'
> echo ${x//,/ }
> b c
> echo ${x/,/ }
> b,c
>

The echo command is consuming the '-e', as it is a flag.  Instead, try
using:

  printf '%s\n' "${x/,/ }"


Re: String replacement drops leading '-e' if replacing char is a space

2023-08-13 Thread Lawrence Velázquez
On Mon, Aug 14, 2023, at 1:27 AM, Eduardo Bustamante wrote:
> The echo command is consuming the '-e', as it is a flag.  Instead, try
> using:
>
>   printf '%s\n' "${x/,/ }"

Also note that echo wouldn't have consumed the "-e" had the expansions
been quoted properly (as Eduardo did in his printf example):

bash-5.2$ x='-e,b,c'
bash-5.2$ echo "${x//,/ }"
-e b c
bash-5.2$ echo "${x/,/ }"
-e b,c


-- 
vq



Re: String replacement drops leading '-e' if replacing char is a space

2023-08-13 Thread Kerin Millar
On Mon, 14 Aug 2023 02:11:27 +
pphick via Bug reports for the GNU Bourne Again SHell  wrote:

> If a string starts with '-e' the replacement operators ${x//,/ } and ${x/, /} 
> drop the '-e'.
> The behaviour seems to be very specific: the string must start with '-e' and 
> the replacing character has to be a space.
> 
> Repeat-By:
> 
> x='-e,b,c'
> echo ${x//,/ }
> b c
> echo ${x/,/ }
> b,c

This is to be expected. Given that you haven't quoted the expansion, word 
splitting occurs, after which echo is run with three arguments. The first of 
these arguments is -e, which is treated as an option.

-- 
Kerin Millar