diff options
author | Roy Marples <roy@marples.name> | 2007-11-22 12:18:24 +0000 |
---|---|---|
committer | Roy Marples <roy@marples.name> | 2007-11-22 12:18:24 +0000 |
commit | 4b28587704ea31788f91f27d71b9aa96a45afc9c (patch) | |
tree | 78414d2a14e6799c40287d3df16fba8183f163c3 | |
parent | 7cf049cb35b03ff3d4e3da6b863c0d17ad3496db (diff) |
Add a yesno function to check the boolean value of a variable
-rw-r--r-- | sh/functions.sh | 18 |
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 |