On Tue, Jun 04, 2024 at 04:40:07PM +0200, Franco Martelli wrote:
> FYI the revision of duhs() I adopt is:
> 
> duhs() { ( shopt -s dotglob; printf '%s\0' "${1:-.}" "${1:-.}"*/ | xargs -0
> du -shl ) }                                                ↑
> 
> Please note that I dropped a "/" in the "${1:-.}"/*/ block because the
> directories listed had a double "//" in their names:

That's because you're passing directories with a trailing / from your
shell.  Probably because you're using tab completions.

If you pass "/usr/local" as the argument instead of

> ~# duhs /usr/local/
> 88K     /usr/local/
> 4,0K    /usr/local//bin/
> 4,0K    /usr/local//etc/
> 4,0K    /usr/local//games/
> 4,0K    /usr/local//include/
> 4,0K    /usr/local//man/
> 4,0K    /usr/local//sbin/
> 60K     /usr/local//share/
> 4,0K    /usr/local//src/

you will see that you've broken it now.

If you really care about removing the double slashes from the case
where you pass an extra trailing slash in your input, you should use
parameter expansions or some other filtering to remove one of the
slashes.  That would be better than breaking your function.

duhs() {
    (
      shopt -s dotglob
      s=${1:-.}
      s=${s%/}
      printf '%s\0' "${s:-.}" "${s:-.}"/*/ | xargs -0 du -shl
    )
}

Reply via email to