5 ms·
Perhaps it's my own shortcoming, but for any given script I write, I find that, say, 20% of all my code is productive, and the remaining 80% is massaging the ou
by pdpi 11y ago
Perhaps it's my own shortcoming, but for any given script I write, I find that, say, 20% of all my code is productive, and the remaining 80% is massaging the output of one tool into a shape that's compatible with the input of the next tool. Compare with the exprience of using Windows PowerShell where cmdlets return objects and you can grab precisely the fields you want with minimum ceremony.
Things are better now with builtin tests, but god help you if you need to use /bin/[ and you end up with idioms like 'if ["x$foo" = "x$bar"]' so that bad things don't happen if $foo starts with a dash, or either variable is empty.
It gets even more fun when you look at the amount of cruft around terminal emulators themselves, and the support for legacy terminals in the command line. Why do modern versions of OSX still ship with /usr/lib/libtermcap.dylib?
Don't get me wrong -- UNIX shells are amazingly powerful tools, but they're just stuck in the 70s and we can do much better today.
- manyxcxi 11y agoI think that's the point- they're amazingly powerful. Additionally with POSIX, you can assume that the command you used on one OS behaves or at least outputs the same on another. I feel like the interface for these commands is exactly what you'd want from a collection of executables that do only one thing. As for shell scripting, you don't have to use bash/sh/whatever. You could write your script or executable in any language that will let you call system commands, so it's really a non-issue if you absolutely can't stand the syntax. I write plenty of bash scripts and I do feel your pain, they're not usually very pleasant if you have to go beyond trivial use cases- but it's also (generally) not impossible.
- saulrh 11y agoIf you like PowerShell, try using jq in your Unix shell pipelines. Ingesting data into json is still a bit finicky, but once you know the patterns you need to use with cut and a csv-to-json tool things become much faster.
- pdpi 11y agoI do love jq :) Hadn't thought of chaining that with a csv-to-json workflow, that's a neat idea -- but if that's the easiest way out, that's clearly a symptom of the problem I'm describing, isn't it?
- saulrh 11y agoQuite possible. I will say that I'd much prefer structured text that I can massage to my liking over an actual object model. Having things print and read JSON streams is just as good as having cmdlets push and pull .net object, except that we can write our programs in languages that aren't .net-aware. And it makes it way easier for the system to interact with systems that don't speak interchange data format, including things like filesystems and websites. One of the things I've been trying to figure out for a while is a way to build a trivial adapter for the csv-to-json | jq pipelines I've been building, something sufficiently easy to use that I could bake it into a |-equivalent extension to something like zsh.
- pjc50 11y agoI keep wanting to like PowerShell but finding it limited in silly ways. Text output is crippled, and there's no sensible way to save the intermediate value of a pipeline in a file. The security ceremony required around PS is also an obstacle to getting started. And of course Microsoft have missed the opportunity to fix the path separator. I admit that Bourne shell is not great for anything over a few lines, and find it better to drop into perl or python where filename-separator issues are mostly eliminated.
- dsp1234 11y agoand there's no sensible way to save the intermediate value of a pipeline in a file Sounds like you are looking for Tee-Object[0]. "Saves command output in a file or variable and also sends it down the pipeline." And of course Microsoft have missed the opportunity to fix the path separator. Windows supports both path separators in pretty much all cases (open files, changing directories, etc) PS C:\> d: PS D:\> cd /projects/node_modules/immutable/node_modules/uglify-js/node_modules PS D:\projects\node_modules\immutable\node_modules\uglify-js\node_modules> Text output is crippled I guess this depends on what you want out of the system. Some options are: "format-table -auto" which provides a nicely formatted table view of the data "format-list" which provides each property on a separate line with a blank line between objects "format-custom" which allows you to create your own views of objects (with a very readable default), which has ultimate flexibility "converto-csv" which output the object as a CSV (or with custom delimiters such as TSV) "converto-html" which outputs the object as an html table (with somewhat customizable markup) "convertto-xml" similar to the above But really, if it's possible, then it makes sense to use the object pipeline until you're done (so that different parts of the pipeline can use different parts of the object). Then spitting out CSV, TSV, XML, etc should get interop with basically every other tool that's going to process text in some way. [0] - https://technet.microsoft.com/en-us/library/hh849937.aspx https://technet.microsoft.com/en-us/library/hh849937.aspx
- pjc50 11y agoText output is chopped at 80 characters unless you specify otherwise, even when directed to a file; I'm probably going to try converto-csv next time I want to input it into python, thanks for the tip. The output of tee-object can't easily be read back in to a new pipeline. I suppose we're supposed to stash it in a variable which will be good enough for 99% of cases.
- imtringued 11y agoHeh kids these days, I bet the next thing you're going to demand is a consistent configuration format that all aplications will use! (a man can dream)
- l1ambda 11y agoI was told XML will solve this.
- StreamBright 11y agoCould not agree more, best thing that could have happened for CLIs is PS. I wish there was something like that for Linux available today.