help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] Awkward behavior of empty arrays


From: Cristian Zoicas
Subject: Re: [Help-bash] Awkward behavior of empty arrays
Date: Fri, 8 Sep 2017 09:39:37 +0200
User-agent: Mozilla/5.0 (X11; Linux i686; rv:43.0) Gecko/20100101 Firefox/43.0 SeaMonkey/2.40



Andy Chu wrote:


    I would also like it if bash would provide a way to safely interpolate 
empty arrays with set -u.  Syntax idea:

    echo "${A[@@]}"

    That way there is no extra mode, which is harder to read IMO.


Given that I already complained that it takes 8 punctuation characters to 
interpolate an array and 10 to copy it [1], I should take this suggestion back.

A simpler and backward compatible syntax would be:

echo "address@hidden"    # like "address@hidden" but an empty array OK with set 
-u

I was thinking of using that syntax for arrays in OSH.  And if you have arrays, you don't really 
need word splitting, so you can argue that address@hidden (no quotes) should be the same as 
"address@hidden".  It's less consistent, but then the common case with fewer characters 
is correct.  Or I might just leave out address@hidden (syntax error) and only provide 
"address@hidden".

Andy


[1] http://www.oilshell.org/blog/2016/11/06.html

My need of using empty arrays was raised exactly from the ideas
mentioned in this document: With arrays you do not have to take
into account or defend against word splitting.

Cristi



reply via email to

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