help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] Is there a way to allow `read` get empty field with IFS=


From: Dennis Williamson
Subject: Re: [Help-bash] Is there a way to allow `read` get empty field with IFS=$'\t'?
Date: Sat, 10 Mar 2018 03:55:43 +0000

On Fri, Mar 9, 2018, 9:41 PM Grisha Levit <address@hidden> wrote:

> >
> > The trailing newline is not removed but read -a does. Is there a way
> > to remove the trailing newline with readarray?
> >
> > $ readarray -t -d $'\t' array <<< $'a\t\tb\tc'
> > $ declare -p array
> > declare -a array=([0]="a" [1]="" [2]="b" [3]=$'c\n')
> >
>
> Yup, that's exactly why I suggested the process substitution method instead
> of here strings.
>
> >
>

It's important to note that in order to include a final empty field, there
must be two tabs at the end of the string. If there is only one, the same
as if there were none, the array will not include a final empty element.

>


reply via email to

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