Tag Info

New answers tagged


You can do this with a shell pattern, rather than a regular expression. Prepend a space to the string so that you don't need to treat the first element differently from the others. if [[ " $DEBUG_PACKAGE_LIST" = *\ libmagick++5-dbg[a-z]* ]]; then (Are you sure about the mandatory letter after -dbg? The package name ends with -dbg.)


In bash 3.2 or above: shopt -u compat31 [[ ! $DEBUG_PACKAGE_LIST =~ [^-[:alnum:]]'libmagick++5-dbg' ]]; In bash 3.1: [[ ! $DEBUG_PACKAGE_LIST =~ '[^-[:alnum:]]libmagick\+\+5-dbg' ]]; (note that [a-z]* is redundant since it also matches the empty string so will always match). Works in both: re='[^-[:alnum:]]libmagick\+\+5-dbg' [[ ! $DEBUG_PACKAGE_LIST ...


You can't quote the regular expression on the right of such an expression (unless you're using a Bash version >= 3.0-alpha and < 3.2-alpha). If you do, it's treated as a comparison between literal strings. Also, Bash uses extended regular expressions for =~, where + is a special character.

Top 50 recent answers are included