Re: Zero-length indexed arrays

2021-12-22 Thread konsolebox
On Wed, Dec 22, 2021 at 4:07 AM Greg Wooledge  wrote:
> I would recommend not using set -u.
> Especially
> when you need to support multiple bash versions, or even multiple shells.

It's still useful during development stages.

-- 
konsolebox



Re: Space vs. non-space separators in COMP_WORDBREAKS

2021-12-22 Thread konsolebox
On Mon, Dec 20, 2021 at 2:21 PM Chet Ramey  wrote:
> Except that turns out not to be useful. It's intuitive to say that
> whitespace separates words and the non-whitespace word break characters
> allow you to complete on parts of words.

But it's still a special case that needs to be documented.  It makes
use of a single parameter but interprets its values differently.

Anyway at least I now know the behavior is intended, so I don't really
mind how this goes.

-- 
konsolebox



Re: Zero-length indexed arrays

2021-12-22 Thread Chet Ramey

On 12/22/21 12:12 AM, Lawrence Velázquez wrote:


 a.  Using ${a[@]} or ${a[*]} with an array without any assigned
 elements when the nounset option is enabled no longer throws
 an unbound variable error.


https://lists.gnu.org/archive/html/bug-bash/2016-07/msg00031.html



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



Re: Zero-length indexed arrays

2021-12-22 Thread L A Walsh






On 2021/12/21 20:07, Greg Wooledge wrote:

On Tue, Dec 21, 2021 at 10:48:07PM -0500, Dale R. Worley wrote:
  

Lawrence Vel�zquez  writes:


Did you mean to say that ${#FOO[*]} causes an error?  Because
${FOO[*]} does not, a la $*:
  

The case that matters for me is the Bash that ships with "Oracle Linux".
Which turns out to be version 4.2.46(2) from 2011, which is a lot older
than I would expect.  But it *does* cause an error in that verison:

$ ( set -u ; FOO=() ; echo "${FOO[@]}" )
bash: FOO[@]: unbound variable




I would recommend not using set -u.  It's not as bad as set -e, but it's
still pretty bad.  It breaks what would otherwise be valid scripts, and
the breakage is not always easy to predict, as you've now seen.


   Not using '-u' in bash is akin to not using 'strict' in perl.  you 
can put int misspelled variables

and not detect them -- and then wonder why your scripts don't work.

If you adhere to always requiring a definition of a variable, then using 
'-u' is never a problem.
But not using '-u', in a script where all variables are defined will 
show unintended errors.


They key is to always require definitions, which is why I always rely on
alias my='declare '
to shorten my declares.