]> git.tuebingen.mpg.de Git - gsu.git/commitdiff
gsu_make_tempfile(): Avoid reading an unbound variable. next
authorAndre Noll <maan@tuebingen.mpg.de>
Thu, 28 Jul 2016 11:56:05 +0000 (13:56 +0200)
committerAndre Noll <maan@tuebingen.mpg.de>
Thu, 28 Jul 2016 12:14:17 +0000 (14:14 +0200)
If a gsu script

(a) enables the -u option to treat unset variables as
    an error for parameter expansion,
(b) does not set TMPDIR,
(c) calls gsu_make_tempfile(),

gsu_make_tempfile() fails with an "TMPDIR: unbound variable" error.

The code already contains a fallback for this case, so we can use
the :- construct to avoid the error and fall back to /tmp if TMPDIR
is unset or NULL.

common

diff --git a/common b/common
index 4e1d115cb8473dd15ccba7c6fac806746cc8e4c7..ec7b8e2cfd816f1faadc6b2ffd8c45c2da37fc28 100644 (file)
--- a/common
+++ b/common
@@ -107,7 +107,7 @@ gsu_make_tempfile()
        if [[ "${template:0:1}" != '/' ]]; then # relative path
                if (($# > 1)); then
                        dir="$2"
-               elif [[ -n "$TMPDIR" ]]; then
+               elif [[ -n "${TMPDIR:-}" ]]; then
                        dir="$TMPDIR"
                else
                        dir="/tmp"