|
Chapter 44 Shell Programming for the Uninitiated
|
|
A
case
statement (
44.5
)
is good at string pattern matching.
Its "wildcard" pattern-matching metacharacters work like the
filename wildcards (
1.16
)
in the shell, with a few twists.
Here are some examples:
-
?)
-
Matches a string with exactly one character like
a
,
3
,
!
, and so on.
-
?*)
-
Matches a string with one or more characters (a non-empty
string).
-
[yY]|[yY][eE][sS])
-
Matches
y
,
Y
or
yes
,
YES
,
YeS
, etc. The
|
means "or."
-
/*/*[0-9])
-
Matches a file pathname, like
/xxx/yyy/somedir/file2
, that starts with a slash, contains at
least one more slash, and ends with a digit.
-
'What now?')
-
Matches the pattern
What now?
.
The
quotes (
8.14
)
tell the shell to treat the string literally: not to break it at
the space and not to treat the
?
as a wildcard.
-
"$msgs")
-
Matches the contents of the
msgs
variable.
The double quotes let the shell substitute the variable's value; the
quotes also protext spaces and other special characters from the
shell. For example, if
msgs
contains
first next
, then
this would match the same string,
first next
.
|
|