1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/bin/bash
# match.bash
# ==========
# Usage: match.bash PATTERN ITEM1 [ITEM2 ...]
#
# Check if any items match a pattern
help_msg() {
cat <<-EOF
Check if any items match a pattern
Usage: match PATTERN ITEM1 [ITEM2 ...]
Options:
-h, --help: print this message
EOF
exit 1
}
err_msg() {
(>&2 echo "$1")
exit 1
}
for i in "$@"; do
case $i in
-h|--help) help_msg;;
esac
done
if [[ $# -lt 2 ]]; then
err_msg "Usage: match.bash PATTERN ITEM1 [ITEM2 ...]"
fi
for item in "${@:2}"; do
if [[ $item == $1 ]]; then
exit 0
fi
done
exit 1