Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> supports the DNS-over-TLS and DNS-over-HTTPS protocols, and can emit JSON

This shows how much our old-school Unix tools need an update.

What if all the CLI tools had an option for JSON output and the shell natively supported a query language like `jq`. Then you could pipe commands together:

    host -t A example.org --json-out | ping -c1 --json-in .arecords[0] --json-out | echo --json-in .[0].time > outputfile
This assumes the default output would still be the legacy text format. But if the default output changed to JSON then you could get rid of the ugly json-in/out syntax.


I think a better way to handle your approach would be to attempt to make it automatic; for example, if a program could detect its output as "not a TTY" and then (somehow) make an intelligent determination about what kind of object to pass (i.e. if there was a way for the program on the other end of the pipe to say "Send me object data if you want!") then it would be useful, coupled with programs or commandlets to do filtering.

Having to manually specify "you, output JSON! And you, input JSON! and also filter based on this difficult to remember for most people syntax!" would be cumbersome; much easier to have "commandlets" built into the shell to handle this sort of thing in a sort of composable pipeline. For example:

    host -t A example.org
        | select arecords --limit 1
        | ping -c1
        | select pings.time --limit 1
        | write --append outputfile
As others have said, Powershell supports this, and it's completely awesome to work with. The fact that (assuming proper metadata on the binaries) I can do queries like this is awesome:

    ~ > Get-Command java -All | Sort-Object Version -Descending
    
    CommandType     Name        Version    Source
    -----------     ----        -------    ------
    Application     java.exe    15.0.1.0   C:\Program Files\Java\jdk-15.0.1\bin\java.exe
    Application     java.exe    11.0.6.0   C:\Program Files\Java\jdk-11.0.6\bin\java.exe
    Application     java.exe    8.0.2610.… C:\Program Files (x86)\Common Files\Oracle\Java\javapath\java.exe
This lets you, for example, have multiple versions of something installed, and have a script easily and cleanly get a list of all of them and either choose which one to use, or run something on each (e.g. for testing scripts).

There are also a lot of "that's weird but handy" features, like being able to interact with environment variables the same way you do local files:

    if (Test-Path 'env:GIT_COMMIT') {
        echo "GIT_COMMIT is $Env:GIT_COMMIT"
        $commit_hash = $Env:GIT_COMMIT
    }
Extremely impressed with Microsoft on this implementation. Also worth noting: you can install Powershell on your Linux or macOS systems and use it there as well. Semi-tempted to try implementing things in Powershell as the only cross-platform shell available.


Like probably dozens of others, I've been idly dreaming about reimplementing coreutils / textutils etc to be able to emit and consume structured records in some serialization format.

The thing that would make this really useful is a(t least one) global database of serialization formats to be a lingua franca between tools. Designing those formats to be useful cross-platform would be tough, but you could start with a format db that only promises linux compat, and later add bsd, and maybe windows even later.

edit: google had something like this internally, the "protodb", a versioned repository of protobuf definitions so that any other tool could consume your tool's output.


Some shells, such as elvish [0], nushell [1], mash [2], and even Windows' powershell do support natively manipulating structured data. There is quite a gap between the shell supporting it and tools supporting it, though, and it's a bit of a chicken-and-egg problem.

[0] https://elv.sh/

[1] https://www.nushell.sh/

[2] http://mash-shell.org/


I find jc useful for exactly this purpose -- https://github.com/kellyjonbrazil/jc


Thanks for mentioning this, looks super useful as a bridge.


This is absolutely violation of the unix spirit!

Don't you know that the output of every tool and the format of every configuration file must have their own unique format?

Not even systemd is allowed to use JSON for config files.

/s


Go try powershell for a bit the UX leap forward in treating everything as an object is immense.


As far as I know, freebsd uses libxo, which allows you to use "--libxo" to choose your output format. I hope linux distros will follow that.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: