Re: String substitution bug

2024-11-25 Thread marcel.plch
On Monday, November 25th, 2024 at 5:49 PM, Chet Ramey  
wrote:

> On 11/23/24 9:29 PM, marcel.plch via Bug reports for the GNU Bourne Again
> SHell wrote:
> 

> > Thank you for clarifictaion.
> > 

> > Maybe adding an extra clarification to the bash manpage
> > in the Pattern Matching section would be a good idea?
> 

> 

> I can add some clarifying text, but I figure that the since this text
> appears in the section describing [...] bracket expressions that it
> would have been reasonable to infer that it describes how pattern
> matching treats characters between those brackets, and that if the
> description of, say, character classes includes additional brackets,
> then those are required.

Not in one place the pattern "[[:space:]]" is mentioned.
I understand that the current formulation of the manpage
sounds rather obvious to you (it does to me as well now
that I get it), but when reading it for the first
time, I thought that the "between [ and ]" part is
speaking of the brackets already contained within
the "[:space:]" expression and that the check of
whether or not this is a class is based on the
fact that the expression has the first brace
followed by a colon and the second brace
lead by a colon.

This small assumption lead me to losing a whole evening
pulling my hair out and 3 (three!) points of reputation
on Stackoverflow [0].

If adding just one sentence containing "[[:space:]]" to
clarify the section a tiny bit more, I think that
it is well worth it.

[0] - https://stackoverflow.com/questions/79219041/bash-string-substitution-bug
-- 

Dormouse

publickey - marcel.plch@proton.me - 0x1094A451.asc
Description: application/pgp-keys


signature.asc
Description: OpenPGP digital signature


String substitution bug

2024-11-23 Thread marcel.plch
Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -march=x86-64 -mtune=generic -O2 -pipe -fno-plt 
-fexceptions -Wp,-D_FORTIFY_SOURCE=3 -Wformat -Werror=format-security   
  -fstack-clash-protection -fcf-protection -fno-omit-frame-pointer 
-mno-omit-leaf-frame-pointer -g 
-ffile-prefix-map=/build/bash/src=/usr/src/debug/bash -flto=auto 
-DDEFAULT_PATH_VALUE='/usr/local/sbin:/usr/local/bin:/usr/bin' 
-DSTANDARD_UTILS_PATH='/usr/bin' -DSYS_BASHRC='/etc/bash.bashrc' 
-DSYS_BASH_LOGOUT='/etc/bash.bash_logout' -DNON_INTERACTIVE_LOGIN_SHELLS
uname output: Linux psappho 6.11.9-arch1-1 #1 SMP PREEMPT_DYNAMIC Sun, 17 Nov 
2024 16:06:17 + x86_64 GNU/Linux
Machine Type: x86_64-pc-linux-gnu

Bash Version: 5.2
Patch Level: 37
Release Status: release

Description:

I am trying to do some file management in bash and I have strings in this 
format:

1 dir/hello.txt
2 dir2/bar.jpg

When I run this substitution:
${FOO/[:space:]*/Hello}
I get this result:
1 dir/hHello

The goal is to substitute everything after the first space (including the 
space) with Hello

Seems like a bug to me. In such a case, please confirm and
I will help to investigate

Repeat-By:
Run this shell script:

FOO="1 dir/hello.txt"
echo ${FOO/[:space:]*/Hello}

Thank you for your time
--
Dormouse


publickey - marcel.plch@proton.me - 0x1094A451.asc
Description: application/pgp-keys


signature.asc
Description: OpenPGP digital signature


Re: String substitution bug

2024-11-23 Thread marcel.plch
On Sunday, November 24th, 2024 at 3:05 AM, Lawrence Velázquez  
wrote:

> On Sat, Nov 23, 2024, at 7:11 PM, marcel.plch via Bug reports for the GNU 
> Bourne Again SHell wrote:
> 

> > I am trying to do some file management in bash and I have strings in
> > this format:
> > 

> > 1 dir/hello.txt
> > 2 dir2/bar.jpg
> > 

> > When I run this substitution:
> > ${FOO/[:space:]*/Hello}
> > I get this result:
> > 1 dir/hHello
> > 

> > The goal is to substitute everything after the first space (including
> > the space) with Hello
> > 

> > Seems like a bug to me.
> 

> 

> It is not a bug. Your pattern is incorrect; you should be using
> "[[:space:]]", not "[:space:]". The former is a bracket expression
> containing the character class expression for the "space" character
> class, while the latter is a bracket expression that matches any
> of the characters ":", "s", "p", "a", "c", or "e".
> 

> $ FOO='1 dir/hello.txt'
> $ echo "${FOO/[[:space:]]*/Hello}"
> 1Hello
> 

> --
> vq

Thank you for clarifictaion.

Maybe adding an extra clarification to the bash manpage
in the Pattern Matching section would be a good idea?

I can imagine I'm not the only one who read this with
a bit of misunderstanding, leading to a few lost hours.
--
Dormouse

publickey - marcel.plch@proton.me - 0x1094A451.asc
Description: application/pgp-keys


signature.asc
Description: OpenPGP digital signature