Saumik Satapathy
Saumik Satapathy

Reputation: 1

Why to use ! symbol and then escape it?

#!/bin/sh
echo "Enter a name"
read name
    case "$name" in
            *[!\ a-zA-Z]*)  echo "Can contain only alphabets" >/dev/tty
            continue;;
            *) echo "Good entry" ;;
    esac

Upvotes: 1

Views: 59

Answers (1)

anubhava
anubhava

Reputation: 785108

This expression:

*[!\ a-zA-Z]*

Has ! at the start which does negation of all characters or ranges present inside [...]. In this case it means anything that is

  • not a space
  • not in the range of a-z
  • not in the range of A-Z

Also note that escaping is for space next to \ not for the preceding ! to avoid word splitting.

Upvotes: 1

Related Questions