Browse code

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

Attila Fazekas authored on 2015/02/24 22:06:56
Showing 3 changed files
... ...
@@ -62,6 +62,9 @@ function trueorfalse {
62 62
     $xtrace
63 63
 }
64 64
 
65
+function isset {
66
+    [[ -v "$1" ]]
67
+}
65 68
 
66 69
 # Control Functions
67 70
 # =================
... ...
@@ -205,16 +205,6 @@ function iniuncomment {
205 205
     $xtrace
206 206
 }
207 207
 
208
-function isset {
209
-    nounset=$(set +o | grep nounset)
210
-    set +o nounset
211
-    [[ -n "${!1+x}" ]]
212
-    result=$?
213
-    $nounset
214
-    return $result
215
-}
216
-
217
-
218 208
 # Restore xtrace
219 209
 $INC_CONF_TRACE
220 210
 
... ...
@@ -196,3 +196,20 @@ if is_ubuntu; then
196 196
         echo "is_package_installed() on deleted package failed"
197 197
     fi
198 198
 fi
199
+
200
+# test isset function
201
+echo  "Testing isset()"
202
+you_should_not_have_this_variable=42
203
+
204
+if isset "you_should_not_have_this_variable"; then
205
+    echo "OK"
206
+else
207
+    echo "\"you_should_not_have_this_variable\" not declared. failed"
208
+fi
209
+
210
+unset you_should_not_have_this_variable
211
+if isset "you_should_not_have_this_variable"; then
212
+    echo "\"you_should_not_have_this_variable\" looks like declared variable. failed"
213
+else
214
+    echo "OK"
215
+fi