Re:I got tired of PHP and Perl, so I tried bash
by h1d on Saturday April 13, 2019 @01:18PM
(#19654367)
while IFS=',' read -r field1 field2 field3 _; do
# do stuff
done
This is the reason we need something better than bash than stick with it until it's been used for 50 years. It's just too cryptic.Fish is better but still looks legacy.
A big part of this was figuring out I could the `read` builtin to parse stuff into local variables:
Also, once everything is on stdin, all the standard unix tools Just Work without having to echo and print everywhere, e.g. something like For me, this turned a lot ugly scripts into primarily a collection of functions that compose nicely via pipelines.Anyway, using `read` works especially nicely with tabular data too. For example, a naive CSV parser might look like