Question

CONDITION="*boss*|*mwc*|*puppet*|*nexus*"

case in ${myvar1}
      ${CONDITION} )
        echo HIT
        ;;
      * )
        echo MISS
        ;;
esac

I have couple of issues with this:

  1. Above code does not work
  2. I want insensitive matches to be hit, eg. "Boss1234" or "system MWc", at the moment I know I can do eg. CONDITION="[mM][wW][cC]" but that is not very useful for longer strings.
Was it helpful?

Solution

Use shopt -s extglob to enable extglob shell option change the condition:

CONDITION="@(*boss*|*mwc*|*puppet*|*nexus*)"

The correct case syntax:

case ${myvar1} in
      ${CONDITION} )
        echo HIT
        ;;
      * )
        echo MISS
        ;;
esac
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top