1

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.

Rui F Ribeiro
  • 56,709
  • 26
  • 150
  • 232

1 Answers1

5

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

Michael Mrozek
  • 93,103
  • 40
  • 240
  • 233