Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This question already has an answer here:

I'm having a hard time getting regex matches to work in a bash case statement.

Example code:

#!/bin/bash                          

str='    word1 word2'

echo "With grep:"
echo "$str" |grep '^\s*\<word1\>'

echo "With case:"
case "$str" in
    '^\s*\<word1\>') echo "$str" ;;
esac

The example works with grep, but not with case... I'm confused, because some simpler regexes work with case. Does case use a different syntax for regex? Am I just not escaping things properly?

share|improve this question

marked as duplicate by Gilles bash Jun 10 '16 at 23:52

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1  
case does not support regex, it supports shell globbing. – heemayl Jun 10 '16 at 17:33
up vote 2 down vote accepted

That is because case doesn't use regex's but bash Pathname Expansion. You can learn more from bash man page or from Bash Reference Manual.

share|improve this answer
    
That's it! Thanks. – Mud Bungie Jun 10 '16 at 17:51

Not the answer you're looking for? Browse other questions tagged or ask your own question.