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 <bug-bash@gnu.org> wrote:
Hello.
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -g -O2 -fstack-protector-strong -Wformat
-Werror=format-security -Wall
uname output: Linux alex 5.16.0-3-amd64 #1 SMP PREEMPT Debian
5.16.11-1
(2022-02-25) x86_64 GNU/Linux
Machine Type: x86_64-pc-linux-gnu
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 ''
Expected behavior:
like for an array with empty element
Code: x=(""); for i in "${x[@]}"; do echo "i is '$i'"; done
Result: i is ''
another example, show that problems occurs only with empty resulted
list
Code: x=("/" "//"); for i in "${x[@]%/}"; do echo "i is '$i'"; done
Result: i is ''
i is '/'
Regards,
Alexey