2 ms·
> Take for example this one-liner: > [program listing...] > In this condensed program of 4 lines, the following happens: Right a "one" liner I see...
by somat 3y ago
> Take for example this one-liner:
> [program listing...]
> In this condensed program of 4 lines, the following happens:
Right a "one" liner I see...
once it gets above roughly 100 characters you are no longer allowed to call it a "one liner"
and style note putting the pipe"|" at the end of the command instead of the beginning acts as a natural break and lets you avoid the backslash escaped newline nonsense.
curl ... |
jq ... |
awk ....
vs
curl ... \
| jq ... \
| awk ...
- yjftsjthsd-h 3y agoIf we're nitpicking the number of lines, I'm way more confused because there is no obvious way that I can see for that to be 4 lines. Either it's a (very long) one liner, or it is as rendered a 5 line example (with the lines starting with curl, jq, sqlite3, sqlite3, and xargs). Where is 4 coming from? (To be clear, this sounds like a complaint, and it kind of is, but I think the article is actually quite good if we just ignore that one basically irrelevant detail)
- leblancfg 3y agoTIL about the pipe/newline, thanks. Edited.
- rgrau 3y agoAnother advantage of pipes at the end is that you can comment lines and the full pipeline still works. Some time ago I wrote a bunch of tips to make more ergonomic bash scripts: https://raimonster.com/scripting-field-guide/index.html https://raimonster.com/scripting-field-guide/index.html Also, Perl's diamond operator does the DWIM thing with files/stdin, and it's used directly as a line iterator. It handles multiple files (or none) in a row, which is a nice plus :) https://perlmaven.com/the-diamond-operator https://perlmaven.com/the-diamond-operator