On Mon, 2015-12-07 at 11:07 -0800, Garrett Cooper wrote: > > On Dec 7, 2015, at 10:13, Ian Lepore <i...@freebsd.org> wrote: > > > > > On Mon, 2015-12-07 at 10:24 +0000, Warner Losh wrote: > > > Author: imp > > > Date: Mon Dec 7 10:24:38 2015 > > > New Revision: 291929 > > > URL: https://svnweb.freebsd.org/changeset/base/291929 > > > > > > Log: > > > Make sure to quote the arg after -n and -z tests. > > > > While I am generally a quoting fanatic and would much rather > > overquote > > than underquote in shell scripts, fyi it's not actually needed for > > the > > -n and -z tests. test(1) and shells seem to be smart enough to see > > the > > ']' (which is just an arg to test, not shell language syntax) and > > know > > there isn't a string in front of it. > > Warner's commit was good. There's a more bulletproof way to do this > to make it more portable (in most cases, not all), but it would be > overkill: > > [ "x$x" != x ] > > Also, his commit protects against variables with spaces in them doing > unexpected things with test(1). > > Thanks, > -NGie
Arrrgggghhhh! No no no no, a thousand times NO. There is NO EXCUSE for that ugly unnecessary xfoo stuff. Quoting properly supplies all the bulletproofing needed for string comparisons. It does look like I was wrong about all shells/test implementations handling the closing bracket for -n and -z as an empty-string indicator though, so quoting is a good solution for that. (Quoting is a good solution for everything, it drives me nuts that I can't use spaces in directory and filenames because so many unix scripts fall on their faces with parameter passing and other tricky quoting situations). -- Ian _______________________________________________ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"