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
This commit is contained in:
Attila Fazekas 2015-02-24 14:06:56 +01:00
parent 4cc060e77c
commit 1bd79596c3
3 changed files with 20 additions and 10 deletions

View File

@ -62,6 +62,9 @@ function trueorfalse {
$xtrace $xtrace
} }
function isset {
[[ -v "$1" ]]
}
# Control Functions # Control Functions
# ================= # =================

View File

@ -205,16 +205,6 @@ function iniuncomment {
$xtrace $xtrace
} }
function isset {
nounset=$(set +o | grep nounset)
set +o nounset
[[ -n "${!1+x}" ]]
result=$?
$nounset
return $result
}
# Restore xtrace # Restore xtrace
$INC_CONF_TRACE $INC_CONF_TRACE

View File

@ -196,3 +196,20 @@ if is_ubuntu; then
echo "is_package_installed() on deleted package failed" echo "is_package_installed() on deleted package failed"
fi fi
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