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
... | ... |
@@ -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 |