Skip to contentSkip to conversation

lib/test.sh: Fix 'unbound variable' error

RFC PATCH New Petr Vorel 2 participants 2 messages May 23, 2017 – Jun 27, 2017

lore
Share & tools
lore

Petr Vorel

author
#0 lore raw

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

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

---
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(-)
testcases/lib/test.sh +2 -2
index 2e4d86809..642f7eacf 100644
@@ -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
 
Signature · 1 line
2.12.2
#1 lore raw

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

Hi!

Quoted 10 lines

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

---
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:-}"

That sounds better to me, maybe with a short comment that we are trying to avoid problems on nounset.

Signature · 2 lines
Cyril Hrubis
[email protected]