bug-bash
[Top][All Lists]
Advanced

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

Re: Bash Manual section 6.7 Arrays should mention array append notation


From: Greg Wooledge
Subject: Re: Bash Manual section 6.7 Arrays should mention array append notation
Date: Thu, 24 Mar 2022 11:24:35 -0400

On Thu, Mar 24, 2022 at 11:12:25AM -0400, Zachary Santer wrote:
> I'm consulting the online manual
> <https://www.gnu.org/software/bash/manual/html_node/index.html>, so if
> you're looking for a version number, that would be 5.1.
> 
> I just now looked at doc/bash.pdf in the git repo on Savannah. No info on
> appending is present under bash-5.2-testing or devel.

> > Talking about the lines with "+=", obviously. I only learned I could
> > do this when I found it in existing code.

If you search the man page for += you can find this paragraph:

       In the context where an assignment statement is assigning a value to  a
       shell variable or array index, the += operator can be used to append to
       or add to the variable's previous value.  This  includes  arguments  to
       builtin  commands  such  as  declare  that accept assignment statements
       (declaration commands).  When += is applied to a variable for which the
       integer attribute has been set, value is evaluated as an arithmetic ex‐
       pression and added to the variable's current value, which is also eval‐
       uated.   When += is applied to an array variable using compound assign‐
       ment (see Arrays below), the variable's value is not unset  (as  it  is
       when  using  =),  and new values are appended to the array beginning at
       one greater than the array's maximum  index  (for  indexed  arrays)  or
       added  as additional key-value pairs in an associative array.  When ap‐
       plied to a string-valued variable, value is expanded  and  appended  to
       the variable's value.

The manual is not meant to be a tutorial.  It's a reference.  Information
may be in a different place than you expected, because things are
typically not repeated more than once.  (The man page is already extremely
long, and repeating things would make it even bigger.)



reply via email to

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