[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Behaviour of test -v with assoc array and quote character in key

From: Chet Ramey
Subject: Re: Behaviour of test -v with assoc array and quote character in key
Date: Mon, 22 Feb 2021 11:47:24 -0500
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.7.1

On 2/15/21 1:28 PM, Daniel Gröber wrote:

On Mon, Feb 15, 2021 at 09:11:48AM -0500, Chet Ramey wrote:
`test' is always going to be problematic here because, as a shell builtin,
its arguments undergo a round of word expansions before it's invoked. It's
difficult to reliably detect the closing bracket in an array subscript as a
result, even if the array subscript expansion didn't perform any expansions
on its own. (Consider what would happen if $1 were `]').

You're absolutely right, I didn't consider the ']' case at all! That would
obviously break. So indeed this just user-error then and not really a bug.

Well, it's less than ideal. This is why I introduced the assoc_expand_once
option, but as many folks on here will tell you, it's not a perfect solution. This is one of the cases where it's not.

I think I have a better way to do it, one that doesn't require using an
extra level of quoting or assoc_expand_once, but I'm not ready to commit
anything yet, and builtins like test/[ and let will always cause problems.


``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet@case.edu    http://tiswww.cwru.edu/~chet/

reply via email to

[Prev in Thread] Current Thread [Next in Thread]