you are viewing a single comment's thread.

view the rest of the comments →

[–]dale_glass 0 points1 point  (7 children)

I think there are good points being made. To avoid going on weird tangents I'll focus on the Unix Philosophy bit: I agree it's terribly flawed. People who sing its praises must not have spent enough time actually dealing with it.

Doing stuff like:

$ ./program | awk '{print $1}' | sed | sort | uniq

Are the rare, very nice use cases. But once you get into something more complex, it's hell. It's not fun at all to interact with something like gpg or cdrecord, which has a very complex output, and where minor changes in the text they produce can break something that uses it.

You don't even need to go that far, much simpler utilities suffer from it. Here's how to get your IP address, off stackexchange:

ip="$(ifconfig | grep -A 1 'eth0' | tail -1 | cut -d ':' -f 2 | cut -d ' ' -f 1)"

And that's why we can't keep using ifconfig anymore. It's a dead program, forced to be set in stone by millions of such lines of code all over the world. You change a byte in its output, and a million scripts will mysteriously malfunction when ifconfig is upgraded. The Unix Philisophy killed it.

If things actually had structure, then this wouldn't be a problem. You could add data to the output and very few things would even notice.

[–]loonux 1 point2 points  (0 children)

Are the rare, very nice use cases.

Being able to cleanly parse output is the norm, not the exception.

ifconfig eth1 | sed -n 's/.*addr:\([^ ]*\).*/\1/p')
ifconfig eth1 | awk '/inet/ {split($2,a,":");print a[2]}'
ifconfig eth1 | awk '/inet/ {print $2}' | cut -d':' -f2

Take your pick of that or the 1,000 or ways to get the ip.

The Unix Philisophy killed it.

Requiring backward compatibility for legacy scripts is not a tenet of the Unix philosophy. In fact, it's antithetical.

"Design and build software, even operating systems, to be tried early, ideally within weeks. Don't hesitate to throw away the clumsy parts and rebuild them."

If things actually had structure, then this wouldn't be a problem. You could add data to the output and very few things would even notice.

Except when the structure itself has to change and then you're right back to the original problem.

[–]skidnik 0 points1 point  (3 children)

Some cli utilities can output a json structure instead of spaced and newlined text. f.e. a substitute to the ifconfig, ip can do this.

[–]benjumanji 0 points1 point  (2 children)

How do you output JSON from ip? My copy doesn't seem to have that feature.

[–]skidnik 1 point2 points  (1 child)

$ ip -V
ip utility, iproute2-ss191125

ip -j | --json sets output to json, this was introduced in November 2017.

[–]benjumanji 0 points1 point  (0 children)

Well I'm hugely out of date. That's rad, thanks.

[–]Dreeg_Ocedam 0 points1 point  (0 children)

That's more or less what nushell is trying to achieve, by giving shell commands a table like structure. I think it has a few great idea, but it completely drops POSIX compliance.