Variable pattern testing 

*Tags*: cmd:case

Sample 0, one line 

 $ case $v in [cC]) echo found;; *) echo not found ;; esac

Sample 1 

# all must be in current directory:
case "$*" in
*/*) echo "nom quitting: I can't handle '/'s." >&2; exit ;;
esac

Sample 2 

case $1 in -[1-9]*)
    n=`expr 1 - "$1"`
    shift
esac

Sample: case sensitives 

Solution 

xsel -p | perl -pe 's/[a-z]/[$&\u$&]/g'
$ echo '*.tar.gz | *.tgz' | perl -pe 's/[a-z]/\[$&\u$&\]/g'
*.[tT][aA][rR].[gG][zZ] | *.[tT][gG][zZ]

Test History 

$ v=c
$ case $v in "c") echo found;; *) echo not found ;; esac
found
$ v=C
$ case $v in "c") echo found;; *) echo not found ;; esac
not found

$ case $v in "[cC]") echo found

*) echo not found ;; esac not found

$ case $v in [cC]) echo found

*) echo not found ;; esac found

[Tip]

!!

[Note]

No quoting!:

  case "$src" in '/*')          # referring to an abs point

will fail to operate while the following is ok:

  case "$src" in /*)            # referring to an abs point

documented on: 2000.08.15 Tue 16:55:16