bug-bash
[Top][All Lists]
Advanced

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

read problem


From: kurt
Subject: read problem
Date: Sat, 24 Sep 2022 17:59:56 +0200
User-agent: Evolution 3.44.1-0ubuntu1

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 <tab>).
        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 <tab>.




reply via email to

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