From 4b28587704ea31788f91f27d71b9aa96a45afc9c Mon Sep 17 00:00:00 2001 From: Roy Marples Date: Thu, 22 Nov 2007 12:18:24 +0000 Subject: Add a yesno function to check the boolean value of a variable --- sh/functions.sh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'sh') 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 -- cgit v1.2.3