[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 6/7] syntax-check: fix violations and implement sc_prohibit_t
From: |
Eric Blake |
Subject: |
Re: [PATCH 6/7] syntax-check: fix violations and implement sc_prohibit_test_const_follows_var. |
Date: |
Mon, 21 Nov 2011 13:07:51 -0700 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:7.0.1) Gecko/20110930 Thunderbird/7.0.1 |
On 11/21/2011 07:47 AM, Gary V. Vaughan wrote:
> To safely use a non-literal first argument to `test', you must
> always prepend a literal non-`-' character, but often the second
> operand is a constant that doesn't begin with a `-' already, so
> always use `test a = "$b"' instead of noisy `test "X$b" = Xa'.
Not true.
test a = "$b"
is just as likely to trigger improper evaluation in buggy test(1)
implementations as:
test "$b" = a
If you cannot guarantee the contents of "$b", then you MUST prefix both
sides of the comparison with x or X. Conversely, if you CAN guarantee
the contents of "$b" (for example, if you did b=$?, then you KNOW that b
is a numeric tring with no problematic characters), then you might as
well use the more idiomatic comparison of variable to constant.
--
Eric Blake address@hidden +1-919-301-3266
Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature
- Re: [PATCH 3/7] tests: migrate tests/sh.test checks to syntax-checks., (continued)
Re: [PATCH 6/7] syntax-check: fix violations and implement sc_prohibit_test_const_follows_var., Stefano Lattarini, 2011/11/21
Re: [PATCH 1/7] syntax-check: fix violations and implement sc_useless_quotes_in_case., Eric Blake, 2011/11/21