[TUHS] Command line options and complexity

Steffen Nurpmeso steffen at sdaoden.eu
Thu Mar 5 09:19:36 AEST 2020


Random832 wrote in
<5019a751-d69a-4839-9a56-b977b275070d at www.fastmail.com>:
 |On Tue, Mar 3, 2020, at 13:44, Adam Thornton wrote:
 |> I've heard people say that there isn't really any alternative to this 
 |> kind of complexity for command line tools, but people who say that have 
 |> never really tried the alternative, something like PowerShell. I have 
 |> plenty of complaints about PowerShell, but passing structured data 
 |> around and easily being able to operate on structured data without 
 |> having to hold metadata information in my head so that I can pass the 
 |> appropriate metadata to the right command line tools at that right 
 |> places the pipeline isn't among my complaints3 
 |> <https://danluu.com/cli-complexity/#fn:W>.
 |> 
 |> Somewhat disingenuous. I mean, yes, that's true, but on the other hand 
 |> it means that you have to keep the "what Powershell commands operate on 
 |> what structure" in your head instead, since you can no longer assume 
 |> the pipelines to be a universal interface.
 |
 |Sure, but "stdin is a sequence of any type, and the argument is an \
 |expression that operates on that type or the name of a property that \
 |that type has" is universal enough.
 |
 |The part that has to operate on a specific structure isn't the command, \
 |it's the arguments.
 |
 |For example, a powershell pipeline to produce a list of files sorted \
 |by modified date is:
 |
 |gci . | sort lastwritetime | select name
 ...
 |*assuming that ls -t didn't exist*, to do this with unix tools that \
 |operate on text you would need:
 |
 |ls -l | [somehow convert the date to a sortable format, probably in \
 |awk] | sort | [somehow pick the filename alone out of the output - \
 |possibly with cut or sed or awk again]
 |
 |and it's very difficult to get tools like awk, sort, and cut to work \
 |on formats that contain more than one field that may contain embedded \
 |spaces (you can just about get away with it for ls output because the \
 |date is always three "words").

Yes, that is really bad, except only that a lot of output is
pretty portables since a very long time.  FreeBSD started using
libxo in many base utilities, which can output in structured
formats.  This includes CSV and even CBOR :), i do not know how
the latter integrates in Unix text utilities however.  (I think
the format string syntax, that a bit originates in QT ??, could
have been warped to something better, like the Python ones, plus
further extensions, however.  But it is an improvement to what the
standard formats end up with when reordering etc. comes into
place.)

--steffen
|
|Der Kragenbaer,                The moon bear,
|der holt sich munter           he cheerfully and one by one
|einen nach dem anderen runter  wa.ks himself off
|(By Robert Gernhardt)


More information about the TUHS mailing list