self-reference to assoc.-array variable

2022-09-15 Thread kurt
Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -g -O2 -flto=auto -ffat-lto-objects -flto=auto 
-ffat-lto-objects -fstack-protector-strong -Wformat -Werror=format-security 
-Wall 
uname output: Linux kurt-OptiPlex-7020 5.15.0-47-generic #51-Ubuntu SMP Thu Aug 
11 07:51:15 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
Machine Type: x86_64-pc-linux-gnu

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

Description:
a declaration like the following was possible before bash-version 5.1:
declare -r -A MYAR=(
  ['first']="NUMBER ONE"
  # --- 'self-reference' to declaring array variable MYAR
  ['top']="${MYAR['first']}"
)
echo "${MYAR[@]}"
now bash complains with a syntax-error on the 
['top']="${MYAR['first']}" construct

Repeat-By:
execute the above example-code




read problem

2022-09-24 Thread kurt
Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -g -O2 -flto=auto -ffat-lto-objects -flto=auto 
-ffat-lto-objects -fstack-protector-strong -Wformat -Werror=format-security 
-Wall 
uname output: Linux kurt-OptiPlex-7020 5.15.0-48-generic #54-Ubuntu SMP Fri Aug 
26 13:26:29 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
Machine Type: x86_64-pc-linux-gnu

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

Description:
read into an array is inconsistent depending on the value of IFS 
(tested with ! and ).
as compared to readarray, which does the expected splitting count on 
both values.

Code to test the problem:

declare -a aa adelim=("!" $'\t')
declare s delim
declare -i i j
for((j=0;j<${#adelim[@]};j++)) do
  delim="${adelim[$j]}"
  printf -- 'delim is >%s<\n' "${delim}"
  s="."
  for((i=0;i<12;i++)) do
if [[ $i -gt 4 && $i -lt 9 ]]; then
  s+="${delim}"
else
  s+="${delim}$i"
fi
  done
  printf -- '  >%s<\n' "$s"
  readarray -d "${delim}" aa <<< "$s"
  printf -- '  len readarray: %d\n' "${#aa[@]}"
  IFS="${delim}" read -a aa <<< "$s"
  printf -- '  len read : %d\n' "${#aa[@]}"
done

Output is:

delim is >!<
  >.!0!1!2!3!4!9!10!11<
  len readarray: 13
  len read : 13
delim is >  <
  >.0   1   2   3   4   
9   10  11<
  len readarray: 13
  len read : 9

Expected for read would also be 13 when IFS is set to .




Re: read problem [SOLVED: works as documented]

2022-09-24 Thread kurt
Thanks for the clarification.

So 'ignoring whitespace' preceeds 'delimiter-logic' in the case of a single 
.

I compared the read and readarray sections and did not have a look at Word 
Splitting.

Sorry to bother.


Am Samstag, dem 24.09.2022 um 11:21 -0500 schrieb Dennis Williamson:
> 
> 
> On Sat, Sep 24, 2022 at 11:02 AM kurt  wrote:
> > Configuration Information [Automatically generated, do not change]:
> > Machine: x86_64
> > OS: linux-gnu
> > Compiler: gcc
> > Compilation CFLAGS: -g -O2 -flto=auto -ffat-lto-objects -flto=auto 
> > -ffat-lto-objects -fstack-protector-strong -Wformat -Werror=format-security 
> > -Wall 
> > uname output: Linux kurt-OptiPlex-7020 5.15.0-48-generic #54-Ubuntu SMP Fri 
> > Aug 26 13:26:29 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
> > Machine Type: x86_64-pc-linux-gnu
> > 
> > Bash Version: 5.1
> > Patch Level: 16
> > Release Status: release
> > 
> > Description:
> >         read into an array is inconsistent depending on the value of IFS 
> > (tested with ! and ).
> >         as compared to readarray, which does the expected splitting count 
> > on both values.
> > 
> > Code to test the problem:
> > 
> >         declare -a aa adelim=("!" $'\t')
> >         declare s delim
> >         declare -i i j
> >         for((j=0;j<${#adelim[@]};j++)) do
> >           delim="${adelim[$j]}"
> >           printf -- 'delim is >%s<\n' "${delim}"
> >           s="."
> >           for((i=0;i<12;i++)) do
> >             if [[ $i -gt 4 && $i -lt 9 ]]; then
> >               s+="${delim}"
> >             else
> >               s+="${delim}$i"
> >             fi
> >           done
> >           printf -- '  >%s<\n' "$s"
> >           readarray -d "${delim}" aa <<< "$s"
> >           printf -- '  len readarray: %d\n' "${#aa[@]}"
> >           IFS="${delim}" read -a aa <<< "$s"
> >           printf -- '  len read     : %d\n' "${#aa[@]}"
> >         done
> > 
> > Output is:
> > 
> >         delim is >!<
> >           >.!0!1!2!3!4!9!10!11<
> >           len readarray: 13
> >           len read     : 13
> >         delim is >      <
> >           >.    0       1       2       3       4                           
> >             9       10      11<
> >           len readarray: 13
> >           len read     : 9
> > 
> > Expected for read would also be 13 when IFS is set to .
> > 
> > 
> 
> From man bash:
> 
>        The shell treats each character of IFS as a delimiter, and splits the 
> results of the other expansions into words on these characters.  If
>        IFS is unset, or its value is exactly , the 
> default, then any sequence of IFS characters serves  to  delimit  words.
>        If IFS has a value other than the default, then sequences of the 
> whitespace characters space and tab are ignored at the beginning and end
>        of the word, as long as the whitespace character is in the value of 
> IFS (an IFS whitespace character).  Any character in IFS that is  not
>        IFS  whitespace,  along  with  any adjacent IFS whitespace characters, 
> delimits a field.  A sequence of IFS whitespace characters is also
>        treated as a delimiter.  If the value of IFS is null, no word 
> splitting occurs.
> 
> Note in particular the next-to-last sentence that begins with "A sequence". 
> IFS is used by read but not readarray which has its own delimiter argument. 
> See the manual sections for the two commands.
>