[LTP] [RFC PATCH 1/1] lib/test.sh: Fix 'unbound variable' error

Petr Vorel pvorel@suse.cz
Tue May 23 10:11:54 CEST 2017


Some distros have set nounset as default, which requires to fix testing
optional variables.

Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
I don't want to disable check with 'set +o nounset' in each script, I think
it's actually quite good to have it. It just requires taking care when using
optional variables. But it might be better to set it at the top:
TST_NO_CLEANUP="${TST_NO_CLEANUP:-}"
LTP_IPC_PATH="${LTP_IPC_PATH:-}"
---
 testcases/lib/test.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/testcases/lib/test.sh b/testcases/lib/test.sh
index 2e4d86809..642f7eacf 100644
--- a/testcases/lib/test.sh
+++ b/testcases/lib/test.sh
@@ -103,11 +103,11 @@ tst_require_root()
 
 tst_exit()
 {
-	if [ -n "$TST_CLEANUP" -a -z "$TST_NO_CLEANUP" ]; then
+	if [ -n "${TST_CLEANUP:-}" -a -z "${TST_NO_CLEANUP:-}" ]; then
 		$TST_CLEANUP
 	fi
 
-	if [ -n "$LTP_IPC_PATH" -a -f "$LTP_IPC_PATH" ]; then
+	if [ -n "${LTP_IPC_PATH:-}" -a -f "${LTP_IPC_PATH:-}" ]; then
 		rm -f "$LTP_IPC_PATH"
 	fi
 
-- 
2.12.2



More information about the ltp mailing list