[Top][All Lists]

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

Re: [Help-bash] Is there a way to read empty string with `read`?

From: Greg Wooledge
Subject: Re: [Help-bash] Is there a way to read empty string with `read`?
Date: Mon, 23 May 2016 10:34:32 -0400
User-agent: Mutt/

On Mon, May 23, 2016 at 09:19:39AM -0500, Peng Yu wrote:
> In this case, is it better to add an option to read treat each tab as a
> separate dilimiter. This will allow bash to read TSV format.

I don't deal with "How can bash be changed to suit my problem".  I deal
with "How can I use bash *right now*, as is, to solve my problem".
What's the point of using bash if you have to patch bash to do it?
The point of bash is that it's nearly ubiquitous across Linux systems,
and fairly common across other Unix-like systems.  Your script has a
reasonably high chance of working on multiple systems, if you stick to
good practices and the portable options of external tools.

If you want something that can *actually* handle full-blown comma
separated value ("csv") input files, including quoted fields with
internal newlines, you wouldn't write it in bash.  You'd use a
language that has a library specially written to parse these files.
Tcl with Tcllib can do it, for example.  I'm sure there must be
modules for Python, Perl, etc.

If you use bash, then you're acknowledging that you are trading
speed, comfort, flexibility, robustness(!), etc. for portability.

In bash, if you don't like the tr \\t \\002 approach, you could write
a nested loop that reads every field one at a time using read -d $'\t'.
I suspect this will be much slower, but I haven't benchmarked it.

reply via email to

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