Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
bash3.2.0 bug
--------------------
bash 3.2.0
--------------------
~$ bash --version
GNU bash, version 3.2.0(1)-release (x86_64-unknown-linux-gnu)
Copyright (C) 2005 Free Software Foundation, Inc.
~$ [[ "hoge" =~ ho.. ]] && echo "${BASH_REMATCH[0]}"
hoge
~$ [[ "hoge" =~ ho(..) ]] && echo "${BASH_REMATCH[0]}"
-bash: syntax error in conditional expression: unexpected token `('
-bash: syntax error near `ho(.'
~$ pattern="ho(..)"; [[ "hoge" =~ $pattern ]] && echo "${BASH_REMATCH[0]}"
hoge
~$ pattern="ho(..)"; [[ "hoge" =~ $pattern ]] && echo "${BASH_REMATCH[1]}"
ge
--------------------
3.2.57
--------------------
~ $ bash --version
GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin16)
Copyright (C) 2007 Free Software Foundation, Inc.
~ $ [[ "hoge" =~ ho.. ]] && echo "${BASH_REMATCH[0]}"
hoge
~ $ [[ "hoge" =~ ho(..) ]] && echo "${BASH_REMATCH[0]}"
hoge
~ $ [[ "hoge" =~ ho(..) ]] && echo "${BASH_REMATCH[1]}"
ge
~ $ pattern="ho(..)"; [[ "hoge" =~ $pattern ]] && echo "${BASH_REMATCH[0]}"
hoge
~ $ pattern="ho(..)"; [[ "hoge" =~ $pattern ]] && echo "${BASH_REMATCH[1]}"
ge
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.