lib/test.sh: Fix 'unbound variable' error
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
@@ -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
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.
Signed-off-by Petr Vorel <[email protected]>---
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]