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.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.
[0] https://elv.sh/
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
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:
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.