There is no significant difference between putting a slash at the end and not doing so. With a slash at the end, you'll get paths containing double slashes if they are constructed like $TMPDIR/something
, but this should have little or no impact. Only if TMPDIR=/
would this make a difference as double-slash at the start of a pathname may be interpreted especially; see On what systems is //foo/bar different from /foo/bar?.
If $TMPDIR
references a directory by naming a symbolic link, that link would not be detectable if the pathname ends with a slash. I.e., if I use TMPDIR=/tmp/dir/
and /tmp/dir
is a symbolic link to elsewhere, then [ -L "$TMPDIR" ]
would always be false since the symbolic link would be dereferenced.
Some utilities may interpret arguments given with a trailing slash character differently from when they do not have a trailing slash. If that is an issue, then use $TMPDIR/.
or ${TMPDIR%/}
when you need to ensure that the argument has no trailing slash, and use $TMPDIR/
or ${TMPDIR%/}/
when you need a trailing slash. The substitution ${TMPDIR%/}
removes the trailing slash if there is one (but would not remove multiple trailing slashes).
Using a trailing slash or not is not enforced by POSIX. In the end, it comes down to personal preference, but it helps to be consistent. Personally, I don't put slashes at the end of variables that hold pathnames in general.
Also related: