Hacker News new | past | comments | ask | show | jobs | submit login

Right, globs are syntactic sugar on top of readdir. Definitely use them when you are in a shell. But in general the solution is to call readdir, or some language facility built directly on top of it. Calling ls and asking it for JSON is the stupid way to do things.



Just curious, how would you approach getting output from utilities like "df", "mount" and "parted"?


Generally speaking, can't you limit/define the output of those commands and parse them that way? like df --portability or --total or --output

And/or use their return codes to verify that something worked or didn't

Or hope your higher level programming language contains built-ins for file system manipulations


How is that any easier than just giving a standardized --json flag?


It doesn't require trying to organize a small revolution across dozens of GNU tools, many authors, and numerous distros...?

I'd love to see standard JSON output across these tools. I just don't see a realistic way to get that to happen in my lifetime.

Maybe a unified parsing layer is more realistic, like an open source command output to JSON framework that would automatically identify the command variant you're running based on its version and your shell settings, parse the output for you, and format it in a standard JSON schema? Even that would be a huge undertaking though.

There are a lot, LOT of command variants out there. It's one thing to tweak the output to make it parseable for your one-off script on your specific machine. Not so easy to make it reusable across the entire *nix world.


With regards to parted, if you only want to query for information, there is "partx" whose output was purposefully designed to be parsed. I have good experiences with it.




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

Search: