by jewel · 11y ago · 0 comments
This isn't a very good example, because it's trivial to do in bash:
locate sublime | grep settings | grep -v backup
(Replace `locate sublime` with `find / | grep sublime` if locate's results are too old.)> select fullpath, bytes from files order by bytes desc limit 5;
This is better. Here it is in bash:
find / -type f -exec stat -c '%s %n' {} \; | sort -nr | head -n 5
Cherry picking another one that stood out to me.> select writeln('/Users/SJohnson/dictionary2.txt', data) from fileslines where fullpath = '/Users/SJohnson/dictionary.txt' order by data;
cd /Users/SJohnson/; sort dictionary.txt > dictionary2.txt
Some of the rest of the examples are trivial in bash, and others look potentially useful. Of course they are trying to demonstrate its capabilities so the examples are contrived. I can see how this would be useful for someone who doesn't know the command-line, but as someone who is proficient in both SQL is pretty verbose.In the real world I'd switch to a scripting language for some of the more complex cases, since they'd be rare.
select fullpath, bytes from files order by bytes desc limit 5;
is infinitely more readable/parseable than: find / -type f -exec stat -c '%s %n' {} \; | sort -nr | head -n 5
Just something exists doesn't mean it isn't an incomprehensible pile.Something like:
gci / -recurse | sort fullname | select fullName, length -first 5
Really doesnt seem that hard in comparison.The nice thing about the verbosity is kind of similar to the point of SQL in that it too has something of a natural language DSL intent (in PowerShell commands are expected to be "Verb-Noun" and verbs for the most part are encouraged to be from a relatively small set of common verbs). This can make it a bear to fully write out without an IDE (and there are multiple choices these days) or tab completion (which gets better with each release).
The benefit however, is that typically you can very easily read someone's PS1 script if it has been written at full verbosity and know what it is doing. It's often very close to self-documenting at that point.
You can sort of choose what level of verbosity you want to encode in your scripts for your sanity at a later date.
That said, I don't know how much time it would genuinely save. As with most of these tools, you shouldn't be installing them on production servers, so you still have to know Bash anyway.
It's especially handy to see what is going on if you wrote it a month ago, and don't remember all the command line switches.
> This is better. Here it is in bash:
> find / -type f -exec stat -c '%s %n' {} \; | sort -nr | head -n 5
This is also a nice example of the biggest problem piped shell commands: each command is executed in isolation. Because of that you miss on many optimizations that are possible when you know the full query.