Regex expression failing in bash
You would need to escape the space when used inside the test construct like that.
if [[ "$vl" =~ ^\ *[{-].* ]]; then
However it’s often considered better practice to store the regex in a variable
pattern='^ *[{-].*'
if [[ "$vl" =~ $pattern ]]; then
Also note this will match zero to unlimited spaces since * is used, if you want to ensure there is at least one space you should use +
Also the .* at the end is not needed since regex doesn’t need to match the entire line.
pattern='^ +[{-]'
Read more here: Source link
