help-bash
[Top][All Lists]
Advanced

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

Re: How to make `read` fail if there is not enough fields in the input?


From: David
Subject: Re: How to make `read` fail if there is not enough fields in the input?
Date: Thu, 5 Dec 2019 13:51:01 +1100

On Thu, 5 Dec 2019 at 13:13, Peng Yu <address@hidden> wrote:
>
> I’d like to know whether there is enough field in a TSV row. But the status 
> code does not return an error code. Is there a way to let read return 
> non-zero if there is not enough fields? Thanks.
>
> $ IFS=$'\t' read -r x y <<< x
> $ echo $?
> 0

$ IFS=$'\t' read -r -a array <<< x && (( "${#array[@]}" == 2 ))
$ echo $?
1
$ IFS=$'\t' read -r -a array <<< x$'\t'y && (( "${#array[@]}" == 2 ))
$ echo $?
0



reply via email to

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