Question Details

No question body available.

Tags

regex bash

Answers (2)

March 17, 2026 Score: 5 Rep: 209,231 Quality: Low Completeness: 40%

I think you're seeing the result of relying on undefined behavior. { is the regexp metacharacter that indicates the start of a repetition expression, e.g. foo =~ fo{2} so it's not obvious what you were hoping that "\{" =~ { would mean. If you meant it to match a literal { then use a regexp that is defined to mean that, i.e. "\{" =~ [{] or "\{" =~ \{

March 17, 2026 Score: 1 Rep: 27,944 Quality: Low Completeness: 40%

Instead of putting regex as is in [[ ]], without quotes, it's much better to define a variable, like

regex="{" [[ "\{" =~ "$regex" ]] && echo "true"