Move under www to ease rsync
This commit is contained in:
29
www/eps/hpr2448/hpr2448_read_and_check.sh
Executable file
29
www/eps/hpr2448/hpr2448_read_and_check.sh
Executable file
@@ -0,0 +1,29 @@
|
||||
#=== FUNCTION ================================================================
|
||||
# NAME: read_and_check
|
||||
# DESCRIPTION: Reads a value (see read_value) and checks it (see check_value)
|
||||
# against an arbitrary long list of Bash regular expressions
|
||||
# PARAMETERS: 1 - Prompt string for the read
|
||||
# 2 - Name of variable to receive the result
|
||||
# 3 - Default value (optional)
|
||||
# 4..n - Valid regular expressions
|
||||
# RETURNS: Nothing
|
||||
#===============================================================================
|
||||
read_and_check () {
|
||||
local prompt="${1:?Usage: read_and_check prompt outputname [default] list_of_regex}"
|
||||
local outputname="${2:?Usage: read_and_check prompt outputname [default] list_of_regex}"
|
||||
local default="${3:-}"
|
||||
|
||||
if ! read_value "$prompt" "$outputname" "$default"; then
|
||||
return 1
|
||||
fi
|
||||
shift 3
|
||||
until check_value "${!outputname}" "$@"
|
||||
do
|
||||
echo "Invalid input: ${!outputname}"
|
||||
if ! read_value "$prompt" "$outputname" "$default"; then
|
||||
return 1
|
||||
fi
|
||||
done
|
||||
|
||||
return 0
|
||||
}
|
||||
Reference in New Issue
Block a user