41 lines
1.0 KiB
Bash
Executable File
41 lines
1.0 KiB
Bash
Executable File
#=== FUNCTION ================================================================
|
|
# NAME: check_value
|
|
# DESCRIPTION: Checks a value against a list of regular expressions
|
|
# PARAMETERS: 1 - the value to be checked
|
|
# 2..n - valid Bash regular expressions
|
|
# RETURNS: 0 if the value checks, otherwise 1
|
|
#===============================================================================
|
|
check_value () {
|
|
local value="${1?Usage: check_value value list_of_regex}"
|
|
local matches=0
|
|
|
|
#
|
|
# Drop parameter 1 then there should be more
|
|
#
|
|
shift
|
|
if [[ $# == 0 ]]; then
|
|
echo "Usage: check_value value list_of_regex"
|
|
return 1
|
|
fi
|
|
|
|
#
|
|
# Loop through the regex args checking the value, counting matches
|
|
#
|
|
while [[ $# -ge 1 ]]
|
|
do
|
|
if [[ $value =~ $1 ]]; then
|
|
(( matches++ ))
|
|
fi
|
|
shift
|
|
done
|
|
|
|
#
|
|
# No matches, then the value is bad
|
|
#
|
|
if [[ $matches == 0 ]]; then
|
|
return 1
|
|
else
|
|
return 0
|
|
fi
|
|
}
|