It isn't even just the newer shells that have solved this, zsh also has a solution out of the box¹. The extensive globbing support in zsh can largely replace `find`, and things like zargs allow you to reuse your common knowledge throughout the shell.
For example, performing your first example with zargs would use regular option separators(`--`), regular expansion(`{1..5}`), and standard shell constructs for the commands to execute.
I'll contrive up an example based around your file counter, but slightly different to show some other functionality.
f() { fs=($1/*(.)); jo $1=$#fs }
zargs -P 32 -n1 -- **/*(/) -- f
That should recursively list directories, counting only the files within each, and output² jsonl that can be further mangled within the shell². You could just as easily populate an associative array for further work, or $whatever. Unlike bash, zsh has reasonable behaviour around quoting and whitespace too.Edit to add: I'm not suggesting zargs is a replacement for parallel, but if you're only using a small subset of its functionality then it may be able to replace that.
¹ https://zsh.sourceforge.io/Doc/Release/User-Contributions.ht...
The scriptability of mpv is really nice if you're the sort of person who likes building your perfect environment, and also a huge pit of addictive time sinks.
As for native shell support for structured data, Powershell is probably the best implementation. In Powershell objects can be piped to other commands and they can be serialized to json, xml, csv, and even html [2]
[1] https://github.com/jpmens/jo [2] https://docs.microsoft.com/en-us/powershell/module/microsoft...
Looks like GPL license. Cool!
jq & jo are the Calvin & Hobbes of the shell: lots of fun together!
A few examples:
- Generate a simple JSON object:
$ jo foo=12 bar=true baz=null
{"foo":12,"bar":true,"baz":"null"}
- Want a nested object? $ jo foo=12 bar=true baz=null thing=$(jo number=57 test=string)
{"foo":12,"bar":true,"baz":"null","thing":{"number":57,"test":"string"}}
- What about arrays? $ jo thing=$(jo number=57 test=string) anarray=$(jo -a 1 2 3 4 5)
{"thing":{"number":57,"test":"string"},"anarray":[1,2,3,4,5]}
- Now let's add some jq magic to sum all the values in the array together: $ jo thing=$(jo number=57 test=string) anarray=$(jo -a 1 2 3 4 5) | jq '.anarray | add'
15
Great stuff :)