On Mon 03 Jun 2024 at 15:03:37 (-0400), Greg Wooledge wrote:
> On Mon, Jun 03, 2024 at 01:11:57PM -0500, David Wright wrote:
> > On Mon 03 Jun 2024 at 10:32:16 (-0400), Greg Wooledge wrote:
> > > duhs() (
> > >     shopt -s dotglob
> > >     printf '%s\0' "${1:-.}"/*/ | xargs -0 du -sh
> > > )
> > > 
> > > I'm not personally fond of this.  It's extremely easy to overlook
> > > the fact that the curly braces have been replaced with parentheses,
> 
> > I guess minimalists would make a one-liner out of that.
> > Myself, I prefer verbosity, and the ability to search and find
> > all my functions with   /function.*{$   in less. For example,
> > I write what is probably my most trivial function in .bashrc as:
> > 
> >   function _Cat_ {
> >       cat
> >   }
> > 
> > rather than:
> > 
> >   _Cat_() { cat; }
> 
> ... I feel like you've just exemplified what I was talking about, missing
> the fact that the curly braces were replaced with parentheses around the
> function body to force a subshell every time it's called.
  _Puss_() ( cat )

if it makes you happy; but no, you made your point about parentheses
perfectly well. It's just that _Cat_ doesn't require a subshell for
/its/ purpose.

> It had nothing to do with how many lines of code were used.  I could
> have written them as
> 
>     duhs() { (shopt -s dotglob; printf '%s\0' "${1:-.}"/*/ | xargs -0 du 
> -sh); }
> 
> and
> 
>     duhs() (shopt -s dotglob; printf '%s\0' "${1:-.}"/*/ | xargs -0 du -sh)
> 
> and the same point would have applied.
> 
> >   function _Cat_ {
> 
> Do note that the "function" keyword is a bash/ksh extension, and not
> part of POSIX sh syntax.  In bash, "x()" and "function x" are identical
> in behavior.  In ksh, they cause two different kinds of variable scoping
> behavior.  Bash also allows "function x()" which ksh does not.
> 
> Just for the record.

Noted. (Franco did mention using bash, and I mentioned .bashrc.)
I'm a bit old for switching shells now!

Cheers,
David.

Reply via email to