bracket needs to be escaped in variable substitution?

2022-10-06 Thread Antoine

Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -g -O2
uname output: Linux z390 5.10.0-16-amd64 #1 SMP Debian 5.10.127-2 
(2022-07-23) x86_64 GNU/Linux

Machine Type: x86_64-pc-linux-gnu

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

Description:

Hello,

When using substitution with variables and opening bracket as string 
"target", the bracket has to be escaped if there is no closing bracket 
and only when a variable is already used in the string.


It wasn't the behavior or previous bash version.

Repeat-By:

$ ./bash --norc
bash-5.2$ var1="qwertyuiop asdfghjkl"
bash-5.2$ var2="_"
bash-5.2$ echo "${var1// /${var2}[${var2}}"
bash: bad substitution: no closing `}' in ${var1// /${var2}[${var2}}

# but the following work as expected (escaped bracket):
bash-5.2$ echo "${var1// /${var2}\[${var2}}"
qwertyuiop_[_asdfghjkl

# also working as expected (with closing bracket):
bash-5.2$ echo "${var1// /${var2}[${var2}]}"
qwertyuiop_[_]asdfghjkl

# also working as expected (no variable before the bracket):
bash-5.2$ echo "${var1// /[${var2}}"
qwertyuiop[_asdfghjkl


--
Antoine



Re: bracket needs to be escaped in variable substitution?

2022-10-06 Thread Antoine
Issue is not reproduced when using a variable as pattern, and it's not 
related the space character in the pattern:


$ ./bash --norc
bash-5.2$ var="abcd efgh ijkl mnop qrst"
bash-5.2$ pattern=" "
bash-5.2$ string="_"

bash-5.2$ echo "${var//${pattern}/${string}[${string}}"
abcd_[_efgh_[_ijkl_[_mnop_[_qrst

bash-5.2$ echo "${var// /${string}[${string}}"
bash: bad substitution: no closing `}' in ${var// /${string}[${string}}

bash-5.2$ echo "${var//a/${string}[${string}}"
bash: bad substitution: no closing `}' in ${var//a/${string}[${string}}


On 06/10/2022 16:52, Antoine wrote:

Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -g -O2
uname output: Linux z390 5.10.0-16-amd64 #1 SMP Debian 5.10.127-2 
(2022-07-23) x86_64 GNU/Linux

Machine Type: x86_64-pc-linux-gnu

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

Description:

Hello,

When using substitution with variables and opening bracket as string 
"target", the bracket has to be escaped if there is no closing bracket 
and only when a variable is already used in the string.


It wasn't the behavior or previous bash version.

Repeat-By:

$ ./bash --norc
bash-5.2$ var1="qwertyuiop asdfghjkl"
bash-5.2$ var2="_"
bash-5.2$ echo "${var1// /${var2}[${var2}}"
bash: bad substitution: no closing `}' in ${var1// /${var2}[${var2}}

# but the following work as expected (escaped bracket):
bash-5.2$ echo "${var1// /${var2}\[${var2}}"
qwertyuiop_[_asdfghjkl

# also working as expected (with closing bracket):
bash-5.2$ echo "${var1// /${var2}[${var2}]}"
qwertyuiop_[_]asdfghjkl

# also working as expected (no variable before the bracket):
bash-5.2$ echo "${var1// /[${var2}}"
qwertyuiop[_asdfghjkl


--
Antoine





cppcheck warnings

2011-09-11 Thread Antoine Balestrat
Hello !
I've just run cppcheck (a static C/C++ code analyzer) against the latest
bash code (freshly cloned from the git repo), and it points out some
interesting issues.
You can see the log here : http://pastebin.com/pZHQShJp

Hope that was useful to you.
Antoine.


Bash 5 incorrectly overrides BASH_COMPAT env variable

2019-04-18 Thread Marc-Antoine Perennou
Hello,

After debugging why the unit tests of paludis (package manager from
Gentoo and Exherbo) were failing with bash 5, I noticed a really weird
behaviour which wasn't present in earlier versions of bash.

All the exemples I could find support the values we're currently
checking for BASH_COMPAT in several environments (namely "3.2" and
"4.2"). Everything works fine with bash 4, but with bash 5, this
variable gets overridden and the new value is respectively "32" or
"42" (notice the missing dot) when using the compat32 option.

A simple reproducer showing how... unexpected the results are:

keruspe@Lou ~ % bash
keruspe@Lou ~ $ echo $BASHOPTS
checkwinsize:cmdhist:complete_fullquote:expand_aliases:extquote:force_fignore:globasciiranges:hostcomplete:interactive_comments:progcomp:promptvars:sourcepath
keruspe@Lou ~ $ echo $BASH_COMPAT

keruspe@Lou ~ $ BASH_COMPAT=3.2 bash
keruspe@Lou ~ $ echo $BASHOPTS # BASH_COMPAT=3.2 causes compat32 to be
added here
checkwinsize:cmdhist:compat32:complete_fullquote:expand_aliases:extquote:force_fignore:globasciiranges:hostcomplete:interactive_comments:progcomp:promptvars:sourcepath
keruspe@Lou ~ $ echo $BASH_COMPAT
3.2
keruspe@Lou ~ $ export BASHOPTS
keruspe@Lou ~ $ bash
keruspe@Lou ~ $ echo $BASHOPTS
checkwinsize:cmdhist:compat32:complete_fullquote:expand_aliases:extquote:force_fignore:globasciiranges:hostcomplete:interactive_comments:progcomp:promptvars:sourcepath
keruspe@Lou ~ $ echo $BASH_COMPAT # launching a new bash with compat32
in BASHOPTS has overriden the value
32


Is it intended that the value has no dot?

Regards,
Marc-Antoine