From 1bd79596c3c5f62cbbef92558156401447a9b5d3 Mon Sep 17 00:00:00 2001 From: Attila Fazekas Date: Tue, 24 Feb 2015 14:06:56 +0100 Subject: [PATCH] Move back isset to the functions-common isset function was moved to config file related functions by accident, this change also simplfies the isset in a bash >=4.2 way. All supported distro has at least bash 4.2. (RHEL6 used 4.1) Change-Id: Id644b46ff9cdbe18cde46e96aa72764e1c8653ac --- functions-common | 3 +++ inc/ini-config | 10 ---------- tests/functions.sh | 17 +++++++++++++++++ 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/functions-common b/functions-common index 48e400dfb1..56fa64a990 100644 --- a/functions-common +++ b/functions-common @@ -62,6 +62,9 @@ function trueorfalse { $xtrace } +function isset { + [[ -v "$1" ]] +} # Control Functions # ================= diff --git a/inc/ini-config b/inc/ini-config index 0d6d169f8b..26401f3917 100644 --- a/inc/ini-config +++ b/inc/ini-config @@ -205,16 +205,6 @@ function iniuncomment { $xtrace } -function isset { - nounset=$(set +o | grep nounset) - set +o nounset - [[ -n "${!1+x}" ]] - result=$? - $nounset - return $result -} - - # Restore xtrace $INC_CONF_TRACE diff --git a/tests/functions.sh b/tests/functions.sh index 874d02230d..126080f1e3 100755 --- a/tests/functions.sh +++ b/tests/functions.sh @@ -196,3 +196,20 @@ if is_ubuntu; then echo "is_package_installed() on deleted package failed" fi fi + +# test isset function +echo "Testing isset()" +you_should_not_have_this_variable=42 + +if isset "you_should_not_have_this_variable"; then + echo "OK" +else + echo "\"you_should_not_have_this_variable\" not declared. failed" +fi + +unset you_should_not_have_this_variable +if isset "you_should_not_have_this_variable"; then + echo "\"you_should_not_have_this_variable\" looks like declared variable. failed" +else + echo "OK" +fi