Re: for loop over parameter expansion of array can miss resulted empty list

2022-03-24 Thread Chet Ramey
On 3/20/22 5:05 PM, Alexey via Bug reports for the GNU Bourne Again SHell 
wrote:



Bash Version: 5.1
Patch Level: 16
Release Status: release

Description:
   If use 'Parameter Expansion', for example 'Remove matching suffix 
pattern', on array and try to iterate over expansion result with for loop, 
may occur that loop body will not be executed at all.


Repeat-By:
   Code: x=("/"); for i in "${x[@]%/}"; do echo "i is '$i'"; done
   Result: none
   Expected result: i is ''


Thanks for the report. This is the same issue as

https://lists.gnu.org/archive/html/bug-bash/2022-03/msg00033.html

It will be fixed in the next release.

Chet
--
``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: Bash Manual section 6.7 Arrays should mention array append notation

2022-03-24 Thread Zachary Santer
I'm consulting the online manual
, 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.

Regards.
Zack


On Tue, Mar 8, 2022 at 10:55 AM Zachary Santer  wrote:

> $ array=( zero one two )
> $ array+=( three four five )
> $ declare -p array
> declare -a array='([0]="zero" [1]="one" [2]="two" [3]="three"
> [4]="four" [5]="five")'
> $ array=( [0]=zero [1]=one [2]=two )
> $ array+=( [3]=three [4]=four [5]=five )
> $ declare -p array
> declare -a array='([0]="zero" [1]="one" [2]="two" [3]="three"
> [4]="four" [5]="five")'
> $ declare -A assoc_array=( [zero]='0' [one]='1' [two]='2' )
> $ assoc_array+=( [three]='3' [four]='4' [five]='5' )
> $ declare -p assoc_array
> declare -A assoc_array='([four]="4" [one]="1" [five]="5" [zero]="0"
> [two]="2" [three]="3" )'
>
> Talking about the lines with "+=", obviously. I only learned I could
> do this when I found it in existing code.
>
> Regards,
> Zack
>


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

2022-03-24 Thread Greg Wooledge
On Thu, Mar 24, 2022 at 11:12:25AM -0400, Zachary Santer wrote:
> I'm consulting the online manual
> , 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.)



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

2022-03-24 Thread Zachary Santer
Neither of Mr. Wooledge's responses made it into my inbox, and they're not
in my spam folder, either. I only saw them upon examining the bug-bash
Archives, wondering if what I was emailing in was getting there.

Thank you, sir, and pardon my misunderstanding.

Regards,
Zack

On Thu, Mar 24, 2022 at 11:12 AM Zachary Santer  wrote:

> I'm consulting the online manual
> , 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.
>
> Regards.
> Zack
>
>
> On Tue, Mar 8, 2022 at 10:55 AM Zachary Santer  wrote:
>
>> $ array=( zero one two )
>> $ array+=( three four five )
>> $ declare -p array
>> declare -a array='([0]="zero" [1]="one" [2]="two" [3]="three"
>> [4]="four" [5]="five")'
>> $ array=( [0]=zero [1]=one [2]=two )
>> $ array+=( [3]=three [4]=four [5]=five )
>> $ declare -p array
>> declare -a array='([0]="zero" [1]="one" [2]="two" [3]="three"
>> [4]="four" [5]="five")'
>> $ declare -A assoc_array=( [zero]='0' [one]='1' [two]='2' )
>> $ assoc_array+=( [three]='3' [four]='4' [five]='5' )
>> $ declare -p assoc_array
>> declare -A assoc_array='([four]="4" [one]="1" [five]="5" [zero]="0"
>> [two]="2" [three]="3" )'
>>
>> Talking about the lines with "+=", obviously. I only learned I could
>> do this when I found it in existing code.
>>
>> Regards,
>> Zack
>>
>


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

2022-03-24 Thread Chet Ramey

On 3/24/22 11:12 AM, Zachary Santer wrote:

I'm consulting the online manual
, 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.


You're looking at two different manuals.

The current doc/bashref.texi contains:

"The @samp{+=} operator will append to a array variable when assigning
using the compound assignment syntax; see @ref{Shell Parameters} above."

The current doc/bash.1 contains:

The += operator will append to a array variable when assigning
using the compound assignment syntax; see
.SM
.B PARAMETERS
above.

It's not useful to have more than a reference to the actual description,
where the rest of the variable assignment syntax is described, in the
section on arrays.

I don't regenerate the printed manuals on every devel branch push. You need
to look at the manual source files.

--
``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: Bash Manual section 6.7 Arrays should mention array append notation

2022-03-24 Thread Zachary Santer
Thank you.

Also, "append to a array variable" should be "append to an array variable".

Regards,
Zack

On Thu, Mar 24, 2022 at 3:46 PM Chet Ramey  wrote:

> On 3/24/22 11:12 AM, Zachary Santer wrote:
> > I'm consulting the online manual
> > , 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.
>
> You're looking at two different manuals.
>
> The current doc/bashref.texi contains:
>
> "The @samp{+=} operator will append to a array variable when assigning
> using the compound assignment syntax; see @ref{Shell Parameters} above."
>
> The current doc/bash.1 contains:
>
> The += operator will append to a array variable when assigning
> using the compound assignment syntax; see
> .SM
> .B PARAMETERS
> above.
>
> It's not useful to have more than a reference to the actual description,
> where the rest of the variable assignment syntax is described, in the
> section on arrays.
>
> I don't regenerate the printed manuals on every devel branch push. You need
> to look at the manual source files.
>
> --
> ``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: Bash Manual section 6.7 Arrays should mention array append notation

2022-03-24 Thread Chet Ramey

On 3/24/22 5:15 PM, Zachary Santer wrote:

Thank you.

Also, "append to a array variable" should be "append to an array variable".


Thanks.

Chet

--
``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/