Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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 ;;
esac

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

1 Answer 1

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

 
discard

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.