Tim Henigan [off-list ref] writes:
+ - Redirection operators should be written with space before, but
+ no space after them. For example:
+ 'echo test >$file' is preferred over
+ 'echo test > $file'
+
If you are using a $file placeholder, then we would need to show readers
that they need to be enclosed in dq to prevent some versions of bash from
giving us a false warning, and explicitly say why.
$ bash
bash$ file='/var/tmp/f i l e'
bash$ >$file
bash: $file: ambiguous redirect
bash$ >"$file"
bash$ ls -1 "$file"
/var/tmp/f i l e
Adding something like this after your two line examples, after updating
them to use "$file" instead, should be sufficient:
Note that even though it is not required by POSIX to double quote
the redirection target in a variable like the above example, our
code does so because some versions of bash issue an warning unless
we do.