4 ms·
The first feature already exists. You write for i in **/*.jpg; gfxcompress $i in Zsh, or shopt -s globstar # (Which you would have in your .bashr
by Symbiote 10y ago
The first feature already exists. You write
for i in **/*.jpg; gfxcompress $i
in Zsh, or
shopt -s globstar # (Which you would have in your .bashrc)
for i in **/*.jpg; do gfxcompress $i; done
in Bash.
Or, if gfxcompress supports multiple arguments, just
gfxcompress **/*.jpg
Treating the output as objects would be an improvement. I write things like
for id in $(< file-containing-ids ); do
r=$(curl -Ss http://api.example.org/get/$id | jq .status)
if [[ $r ...
...
done
or the more traditional columnar output and awk, but it would be nice if the shell knew about this, enabling tab completion and avoiding a lot of boilerplate.
- Udo 10y agoI was afraid someone might come in and declare this a non-problem, or school me on the example I chose in an effort to invalidate my overall argument. For every example I could conceivably come up with, there is a locally optimal arcane way of achieving a good result. That's not what this is about. Functional (im)possibility was not the message of my argument, ease of use and structural cleanliness was. The issue here is not really finding a "better" way to implement this exact example, it's finding a better mechanism for what the example represents. Can you make everything work with today's tools? Absolutely. Can you do it without arcane switches and weird corner cases? Mostly not. The question I'm raising is more whether this pain is inevitable or not.
- Symbiote 10y agoA shell for loop is not arcane — that's one of the shell's most basic control structures. It uses one fewer external command (no "find"), which is a great way to avoid the weird (and common) corner cases. But anyway, I think you missed where I wrote, "treating the output as objects would be an improvement", and presented a better example in support of your suggestion.
- Udo 10y ago> But anyway, I think you missed where I wrote, "treating the output as objects would be an improvement" We already agree about that part (at least sort of). Instead I wanted to address the part where you declared my example invalid and where we're talking about nothing else but the details of this one example. Did I choose it poorly? Was it too simplistic? Maybe, it really depends on your tastes. I content that arguing about whether or not the find command is usefully implemented is besides the point. The problem lies deeper and is more systemic than that. I'm not arguing that a loop construct is arcane, I'm arguing that in practice such scripts turn arcane really quickly, and that there is something substantial to be gained from having tools exchange information in a structured, machine-centric format - and also from switching to a human-centric control format.
- MichaelBurge 10y agoThe glob breaks if you have a lot of files, or if you're in a deeply nested folder so the full filepaths are long. So the find command is better for a general-purpose script. You also didn't some variables, which can cause problems in a general-purpose tool.