Re: [Help-bash] Is there a way to allow `read` get empty field with IFS=
From:
Grisha Levit
Subject:
Re: [Help-bash] Is there a way to allow `read` get empty field with IFS=$'\t'?
Date:
Fri, 09 Mar 2018 05:47:07 +0000
On Wed, Mar 7, 2018 at 4:53 PM Peng Yu <address@hidden> wrote:
> When IFS=$'\t', `read` will not get empty fields like the one between
> 'a' and 'b c' below. Is there a way to allow it do so? Thanks.
>
You can use mapfile with -d like
$ mapfile -t -d $'\t' a < <(printf 'a\t\tb c\td')
$ declare -p a
declare -a a=([0]="a" [1]="" [2]="b c" [3]="d")