Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1Q7DFT-00045C-I9 for mharc-grub-devel@gnu.org; Tue, 05 Apr 2011 16:53:15 -0400 Received: from [140.186.70.92] (port=58472 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q7DFR-00044A-Mt for grub-devel@gnu.org; Tue, 05 Apr 2011 16:53:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Q7DFO-0002Uf-Hn for grub-devel@gnu.org; Tue, 05 Apr 2011 16:53:13 -0400 Received: from smarthost02.mail.zen.net.uk ([212.23.3.141]:42389) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q7DFO-0002UQ-94 for grub-devel@gnu.org; Tue, 05 Apr 2011 16:53:10 -0400 Received: from [82.69.40.219] (helo=riva.pelham.vpn.ucam.org) by smarthost02.mail.zen.net.uk with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.63) (envelope-from ) id 1Q7DFM-0002R4-Fg for grub-devel@gnu.org; Tue, 05 Apr 2011 20:53:08 +0000 Received: from cjwatson by riva.pelham.vpn.ucam.org with local (Exim 4.72) (envelope-from ) id 1Q7DFL-0002lf-7y for grub-devel@gnu.org; Tue, 05 Apr 2011 21:53:07 +0100 Date: Tue, 5 Apr 2011 21:53:06 +0100 From: Colin Watson To: grub-devel@gnu.org Message-ID: <20110405205306.GJ9163@riva.ucam.org> References: <1302008107.14852.20.camel@alexander> <4D9B6A7D.4090306@gmail.com> <1302031960.30533.7.camel@localhost> <4D9B7692.2020309@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <4D9B7692.2020309@gmail.com> User-Agent: Mutt/1.5.20 (2009-06-14) X-Originating-Smarthost02-IP: [82.69.40.219] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 212.23.3.141 Subject: Re: [PATCH] add proper variable quoting to grub-mkconfig_lib (Debian bug #612417) X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 05 Apr 2011 20:53:14 -0000 On Tue, Apr 05, 2011 at 10:07:46PM +0200, Nicolas de Pesloüan wrote: > On the same kind of things, the construct if test "x$foo" = "x" is > pointless. It is a very strange heritage from DOS, where IF x%A = x > was a common construct, because DOS (command.com) lack quoting. (Is > wasn't possible to write IF "%a" = ""). In shell, "" is an empty > string, but a real argument to commands. The following construct is > the good one : if test "$foo" = "". The test command will receive > three arguments: the value of $foo, the = sign and an empty argument > and will return true if $foo happens to be empty. Actually, it's more relevantly a heritage from pre-POSIX shells, which became habit for many GNU programmers via Autoconf. Here's what the Autoconf documentation has to say on the subject: `test' (strings) Posix says that `test "STRING"' succeeds if STRING is not null, but this usage is not portable to traditional platforms like Solaris 10 `/bin/sh', which mishandle strings like `!' and `-n'. Posix also says that `test ! "STRING"', `test -n "STRING"' and `test -z "STRING"' work with any string, but many shells (such as Solaris, AIX 3.2, UNICOS 10.0.0.6, Digital Unix 4, etc.) get confused if STRING looks like an operator: $ test -n = test: argument expected $ test ! -n test: argument expected Similarly, Posix says that both `test "STRING1" = "STRING2"' and `test "STRING1" != "STRING2"' work for any pairs of strings, but in practice this is not true for troublesome strings that look like operators or parentheses, or that begin with `-'. It is best to protect such strings with a leading `X', e.g., `test "XSTRING" != X' rather than `test -n "STRING"' or `test ! "STRING"'. Solaris 10 is not that old, and this has long been a problem for users of /bin/sh on Solaris in particular. Note that GRUB works on Solaris. I would be interested to know if OpenSolaris, or even Illumos, still uses a pre-POSIX /bin/sh. In most cases, of course, this doesn't matter since it only affects certain strings. But on packages that run on Solaris I am always extremely reticent to change existing code to assume POSIX shell, even if I might write new code that way. When I can assume POSIX shell, your version: if test "$foo" = "" is needlessly verbose. The standard stipulates that this works just fine: if test "$foo" > Writing solid code imply - in particular - knowing the exact behaviors > of the programming language :-) On Unix-like systems, though, and particularly when it comes to shell, this often involves knowing about historical behaviour as well as current behaviour. -- Colin Watson [cjwatson@ubuntu.com]