Sujet : Over-Elaborate Shell Scripting
De : ldo (at) *nospam* nz.invalid (Lawrence D'Oliveiro)
Groupes : comp.unix.shellDate : 23. Mar 2024, 06:38:00
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <utlpro$3fai5$1@dont-email.me>
User-Agent : Pan/0.155 (Kherson; fc5a80b8)
When using a computer, laziness is a virtue. This is why we have
command lines, to help automate the boring and repetitive tasks.
This article
<
https://arstechnica.com/gadgets/2021/09/command-line-wizardry-part-two-variables-and-loops-in-bash/>
continues the author’s intro to basic command-line concepts. But it
repeats a failing I see all too often in shell scripting: doing complex
parsing of the output of some command, when the command itself offers an
option to produce something closer to the exact output you need.
In this case, he is extracting the names of datasets from the “zfs
list” command. And while I have zero experience with ZFS, I can look at
documentation
<
https://docs.oracle.com/cd/E18752_01/html/819-5461/gazsu.html>, and
discover that the command offers the “-o” option where you can select
exactly that information you want it to output. It even has “-H” to
simplify the output format right down, specifically to make it easier
to parse.
Sure, it’s fun to write code. But it can be even more fun to _avoid_
writing code. RTFM helps.