Add a yesno function to check the boolean value of a variable

This commit is contained in:
Roy Marples 2007-11-22 12:18:24 +00:00
parent 7cf049cb35
commit 4b28587704

View File

@ -101,6 +101,24 @@ uniqify() {
echo "${result# *}"
}
yesno()
{
[ -z "$1" ] && return 1
case "$1" in
[Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1) return 0;;
[Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0) return 1;;
esac
local value=
eval value=\$${1}
case "${value}" in
[Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1) return 0;;
[Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0) return 1;;
*) vewarn "\$${1} is not set properly"; return 1;;
esac
}
KV_to_int() {
[ -z $1 ] && return 1