« first day (225 days earlier)      last day (2174 days later) » 

7:23 AM
@Zanna An elegant way?
I don't actually know an elegant way. But for a way that tolerates weird filenames, I would probably use:
#!/usr/bin/env python3

import os

dc = fc = 0
for _, _, fs in os.walk('.'):
    c = sum(f.endswith('.c') for f in fs)
    if c:
        dc += 1
        fc += c
print(dc, fc)
 
7:45 AM
very nice
that os.walk thing is good stuff
I should ask a question about how to count all the .c files and directories that contain them...
 
 
1 hour later…
8:59 AM
@Zanna Should the extended information be in a separate answer rather than your answer? Should I post an answer? I'm pretty inclined to think that it would not be better for me to do that than for your answer to be edited, but you might convince me otherwise, I suppose. :)
@Zanna If you do, then you may want to either (a) state precisely what you consider to be a file and what you consider to be a directory -- for example, what of a symlink whose name ends in .c that points to a file, what of a symlink whose name ends in .c that points to a directory, what if a symlink whose name ends in .c that is broken -- or (b) leave that open-ended but acknowledge those distinctions explicitly so that answerers will think to mention how their answers behave.
For example, the Python script I showed above does not always behave the same as your shell script, even in the absence of weird filenames, because the restriction find imposes for -type f is very strong, excluding everything that is not actually a regular file, including symlinks to any type of file.
Note that I do not mean this as expressing that I have the urge to write a good answer that presents my Python script. I might be persuaded to do it, or you could write an answer with it that includes the details of how it treats different types of files and how to adjust that. (There are of course other possibilities. Plus, you might decide against making those sorts of distinctions an explicit topic of the question, which is totally your choice.)
 
9:22 AM
@EliahKagan I did edit my answer. But still not really happy with the situation
@EliahKagan good point
 
@Zanna Ah -- so you did. Sorry!
In what way are you unsatisfied with it, then?
 
no need to be sorry... I should have mentioned, or perhaps waited, because the idea that you should post a separate answer might be the best one
I don't know... feels more like something that got patched along the way instead of knowing what it was about at the outset
 
9:54 AM
Do you mean that it feels like the added information arising from the comments and from here feels tacked on and not presented in the ideal order? If so, then I think that could be addressed just by changing the order and by showing both regexes for each method.
So, for example, you should show recursive globbing with both regexes, you could then say how to go just one level deep with a nonrecursive glob, and then for the find ... -exec and find ... -execdir methods you could show it with both regexes. I am unsure if this is the best way, but it's a possible way of integrating the changes.
* could show
 
10:16 AM
@Zanna I mean that it behaves like:
#!/bin/sh
set -f
$*
 
10:56 AM
The problem is that I am wrong -- it doesn't behave like that.
It behaves like this, I think:
#!/bin/sh
sh -c "$*"
 

« first day (225 days earlier)      last day (2174 days later) »