

I’m asking why, though. The “variable only” thing doesn’t make sense. If you’re worried about it being unset or not pointing to a directory, use test / [ with -n or -d. If you can’t trust your own script to not change the variable, that’s a hell of a threat model and you shouldn’t remove anything.
Then if you’re wanting to only remove the directory if it has a
testssubdir, the typical way would be to check[ -d "$TEMPDIR"/tests ]before recursively removing$TEMPDIR. No need for thecds or double remove.