bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bracket needs to be escaped in variable substitution?


From: Antoine
Subject: bracket needs to be escaped in variable substitution?
Date: Thu, 6 Oct 2022 16:52:39 +0200
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.3.1

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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]