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

I am not an expert at Unix scripting. An answer to another question suggests using the following piece of code in a script:

case ":$PATH:" in
  *:$HOME/mydir:*) echo it is in the path;;
  *) echo not there ;;

The purpose of this code is to check whether $HOME/mydir is in $PATH, but the examples in this and this suggest exact 'matching' rather than 'contains'.

How is 'case' operating here? Thanks.

share|improve this question
up vote 5 down vote accepted

case is an exact match, but * means "match anything", and the case starts and ends with a *, so it will match any string that contains :$HOME/mydir:. The second case will match anything, but only if the first condition didn't match

share|improve this answer
Ok, thanks. I get it now. – JVerstry Feb 19 '12 at 10:27

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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