bug-bash
[Top][All Lists]
Advanced

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

regex string ">(...)" in [[ ]] command recognize as process substitution


From: Hyunho Cho
Subject: regex string ">(...)" in [[ ]] command recognize as process substitution
Date: Mon, 31 Oct 2022 14:31:36 +0900

######################################################

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-security -Wall
uname output: Linux EliteBook 5.19.0-23-generic #24-Ubuntu SMP
PREEMPT_DYNAMIC Fri Oct 14 15:39:57 UTC 2022 x86_64 x86_64 x86_64
GNU/Linux
Machine Type: x86_64-pc-linux-gnu

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

######################################################

I don't know if this is really a bug or not.
but the regex string ">(...)" in [[ ]] command is recognized as
process substitution
when using "( )" parentheses.

#########  this all works fine #############

val="delete <uuid|vmname> unset"

bash$ regex='(.*) <[^>]*> (.*)'
bash$ [[ $val =~ $regex ]] && echo yes
yes

bash$ [[ $val =~ (.*)\ \<[^\>]*\>\ (.*) ]] && echo yes
yes

bash$ [[ $val =~ ((.*) <[^>]*> (.*)) ]] && echo yes
yes

########  remove spaces in regex string  ######

bash$ regex='(.*)<[^>]*>(.*)'
bash$ [[ $val =~ $regex ]] && echo yes
yes

bash$ [[ $val =~ (.*)\<[^\>]*\>(.*) ]] && echo yes
yes

# this is an error
# [[ ]] command recognizes ">(.*)" as process substitution.
bash$ [[ $val =~ ((.*)<[^>]*>(.*)) ]] && echo yes      # Error !
bash$ .*: command not found
^C

# if i escape \> then the error goes away
bash$ [[ $val =~ ((.*)<[^>]*\>(.*)) ]] && echo yes     # Ok
yes

################  The Second problem  #################

This only happens in the terminal.

# 1. intentionally makes an error by removing escape "\>" to ">"
bash$ [[ $val =~ (.*)\ \<[^\>]*>\ (.*) ]] && echo yes
bash: syntax error in conditional expression: unexpected token `>'

# 2. fixed the error with \> escape, but the error continues
bash$ [[ $val =~ (.*)\ \<[^\>]*\>\ (.*) ]] && echo yes
bash: syntax error near unexpected token `$val'

# 3. On the second try, the error goes away.
bash$ [[ $val =~ (.*)\ \<[^\>]*\>\ (.*) ]] && echo yes
yes

################  The third problem  #################

This also happens only in the terminal.
but very unexpectedly happens

# 1. command executed successfully
bash$ [[ $val =~ (.*)\ \<[^\>]*\>\ (.*) ]] && echo yes
yes

# 2. but the output of the ${BASH_REMATCH[1]} variable is incorrect.
bash$ echo ${BASH_REMATCH[1]}
${         # or something like "${BASH_RE"

bash$ echo ${BASH_REMATCH[1]}
${

# 3. if i try again, it outputs normally.
bash$ [[ $val =~ (.*)\ \<[^\>]*\>\ (.*) ]] && echo yes
yes

bash$ echo ${BASH_REMATCH[1]}
delete



reply via email to

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