[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: String substitution bug
From: |
Lawrence Velázquez |
Subject: |
Re: String substitution bug |
Date: |
Sat, 23 Nov 2024 21:05:59 -0500 |
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
- String substitution bug, marcel.plch, 2024/11/23
- Re: String substitution bug,
Lawrence Velázquez <=
- Re: String substitution bug, marcel.plch, 2024/11/23
- Re: String substitution bug, Andreas Kähäri, 2024/11/24
- Re: String substitution bug, Martin D Kealey, 2024/11/24
- Re: String substitution bug, Oğuz, 2024/11/24
- Re: String substitution bug, Martin D Kealey, 2024/11/25
- Re: String substitution bug, Zachary Santer, 2024/11/25
- Re: String substitution bug, Martin D Kealey, 2024/11/25
- Re: String substitution bug, Mike Jonkmans, 2024/11/26
- Re: String substitution bug, Zachary Santer, 2024/11/26
- Re: String substitution bug, Greg Wooledge, 2024/11/24