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.


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

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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