aboutsummaryrefslogtreecommitdiff
path: root/sh/functions.sh
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2007-11-22 12:18:24 +0000
committerRoy Marples <roy@marples.name>2007-11-22 12:18:24 +0000
commit4b28587704ea31788f91f27d71b9aa96a45afc9c (patch)
tree78414d2a14e6799c40287d3df16fba8183f163c3 /sh/functions.sh
parent7cf049cb35b03ff3d4e3da6b863c0d17ad3496db (diff)
Add a yesno function to check the boolean value of a variable
Diffstat (limited to 'sh/functions.sh')
-rw-r--r--sh/functions.sh18
1 files changed, 18 insertions, 0 deletions
diff --git a/sh/functions.sh b/sh/functions.sh
index 99c83989..2be38a65 100644
--- a/sh/functions.sh
+++ b/sh/functions.sh
@@ -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