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 loo

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

2022-03-22 Thread Lawrence Velázquez
On Tue, Mar 22, 2022, at 11:05 PM, L A Walsh wrote: > On 2022/03/22 14:04, Lawrence Velázquez wrote: >> On Tue, Mar 22, 2022, at 4:53 PM, L A Walsh wrote: >> >>> On 2022/03/21 03:40, Alex fxmbsw7 Ratchev wrote: >>> i solve this by shopt -s nullglob > Repeat-By:

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

2022-03-22 Thread Greg Wooledge
On Tue, Mar 22, 2022 at 08:05:21PM -0700, L A Walsh wrote: > > > > > Repeat-By: > > > > >Code: x=("/"); for i in "${x[@]%/}"; do echo "i is '$i'"; done > > > > >Result: none > > > > >Expected result: i is '' > Sorry, I got sidetracked. In this case it wouldn't matter, > if you have n

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

2022-03-22 Thread L A Walsh
On 2022/03/22 14:04, Lawrence Velázquez wrote: On Tue, Mar 22, 2022, at 4:53 PM, L A Walsh wrote: On 2022/03/21 03:40, Alex fxmbsw7 Ratchev wrote: i solve this by shopt -s nullglob Repeat-By: Code: x=("/"); for i in "${x[@]%/}"; do echo "i is '$i'"; done Result: none

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

2022-03-22 Thread L A Walsh
On 2022/03/22 13:53, L A Walsh wrote: On 2022/03/21 03:40, Alex fxmbsw7 Ratchev wrote: i solve this by shopt -s nullglob Repeat-By: Code: x=("/"); for i in "${x[@]%/}"; do echo "i is '$i'"; done Result: none Expected result: i is '' BTW -- try adding "-u" on your bas

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

2022-03-22 Thread Lawrence Velázquez
On Tue, Mar 22, 2022, at 4:53 PM, L A Walsh wrote: > On 2022/03/21 03:40, Alex fxmbsw7 Ratchev wrote: >> i solve this by shopt -s nullglob >> >>> >>> Repeat-By: >>>Code: x=("/"); for i in "${x[@]%/}"; do echo "i is '$i'"; done >>>Result: none >>>Expected result: i is '' >>> > if

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

2022-03-22 Thread L A Walsh
On 2022/03/21 03:40, Alex fxmbsw7 Ratchev wrote: i solve this by shopt -s nullglob Repeat-By: Code: x=("/"); for i in "${x[@]%/}"; do echo "i is '$i'"; done Result: none Expected result: i is '' if you have nullglob set, then that is not the correct result. I used: #!/bin/bas

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

2022-03-21 Thread Greg Wooledge
On Mon, Mar 21, 2022 at 02:47:12PM -0400, Lawrence Velázquez wrote: > On Mon, Mar 21, 2022, at 8:50 AM, Alexey via Bug reports for the GNU Bourne > Again SHell wrote: > > I can add one more example, which change array size while it's not > > expected behavior: > > x=("/"); y=("${x[@]%/}"); echo "

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

2022-03-21 Thread Lawrence Velázquez
On Mon, Mar 21, 2022, at 8:50 AM, Alexey via Bug reports for the GNU Bourne Again SHell wrote: > I can add one more example, which change array size while it's not > expected behavior: > x=("/"); y=("${x[@]%/}"); echo "x size: ${#x[@]}, y size: ${#y[@]}" This discrepancy seems to have been intro

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

2022-03-21 Thread Alexey via Bug reports for the GNU Bourne Again SHell
I can add one more example, which change array size while it's not expected behavior: x=("/"); y=("${x[@]%/}"); echo "x size: ${#x[@]}, y size: ${#y[@]}" Goal of this example show that it is not only for loop issue.

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

2022-03-21 Thread Greg Wooledge
Stop. Posting. Upside-down. > > On Sun, Mar 20, 2022, 22:07 Alexey via Bug reports for the GNU Bourne > > > Repeat-By: > > > Code: x=("/"); for i in "${x[@]%/}"; do echo "i is '$i'"; done > > > Result: none > > > Expected result: i is '' > On 2022-03-21 14:40, Alex fxmbsw7 Ratchev wrote: > > i

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

2022-03-21 Thread Alexey via Bug reports for the GNU Bourne Again SHell
nullglob is not applicable in this situation, because no 'Pathname Expansion' is occur. On 2022-03-21 14:40, Alex fxmbsw7 Ratchev wrote: i solve this by shopt -s nullglob On Sun, Mar 20, 2022, 22:07 Alexey via Bug reports for the GNU Bourne Again SHell wrote: Hello. Machine: x86_64

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

2022-03-21 Thread Alex fxmbsw7 Ratchev
i solve this by shopt -s nullglob On Sun, Mar 20, 2022, 22:07 Alexey via Bug reports for the GNU Bourne Again SHell wrote: > Hello. > > Machine: x86_64 > OS: linux-gnu > Compiler: gcc > Compilation CFLAGS: -g -O2 -fstack-protector-strong -Wformat > -Werror=format-security -Wall > uname output: L