Backup directories with space in directory name

Colin Watson cjwatson at ubuntu.com
Sat Dec 31 11:55:26 UTC 2016


[Shell nerdery ahead - safe to ignore]

On Sat, Dec 31, 2016 at 04:12:18PM +1100, Karl Auer wrote:
> On Fri, 2016-12-30 at 21:47 -0600, Jack McGee wrote:
> > # Setup variables for the archive filename.
> > day=$(date +%A)
> > hostname=$(hostname -s)
> 
> I'm ignoring all that stuff, but check with debug statements that it
> doesn't generate filenames with spaces in them, or wrap them in quotes
> if it does.

This is in fact one of the places where quoting is unnecessary but
harmless.  The right-hand side of variable assignments does not undergo
any of the expansions that can change the number of words of the
expansion [1], with the exception of the special behaviour of "$@" which
isn't made use of here, so it is safe to not quote $-expansions in this
case.

That said, I always quote them anyway, since it's easier to remember a
rule with fewer exceptions and with strict quoting it's less likely that
somebody will accidentally refactor it into an unsafe form later.

[1] http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_09_01

-- 
Colin Watson                                       [cjwatson at ubuntu.com]




More information about the ubuntu-users mailing list