for data preservation, use mapfile, at least try, ..
On Thu, Jun 24, 2021, 16:17 Peng Yu <pengyu.ut@gmail.com> wrote:
> Hi,
>
> I currently use the following code to get the TSV header into an array.
>
> IFS= read -r line
> readarray -t -d $'\t' array <<< "$line"
> array[-1]=${array[-1]%$'\n'}
>
> The following won't work, as it removes empty fields.
>
> $ IFS=$'\t' read -r -a x <<< $'a\t\tb\t'; declare -p x
> declare -a x=([0]="a" [1]="b")
>
> But the first method is a little long to write. Is there a more
> concise but still robust way to do so in bash?
>
> --
> Regards,
> Peng
>
>