bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: problem anomalies , possibly aliases related


From: Greg Wooledge
Subject: Re: problem anomalies , possibly aliases related
Date: Thu, 20 Jul 2023 09:28:10 -0400

On Thu, Jul 20, 2023 at 11:03:35PM +1000, Martin D Kealey wrote:
> On Thu, 20 Jul 2023, 18:03 Grisha Levit, <grishalevit@gmail.com> wrote:
> 
> > Sounds like you want all the commands in the alias to be executed as a
> > group -- so you can just write it as one:
> >
> > alias bad='{ echo fail; continue; }'
> >
> 
> That right there USED to work as a function:
> 
>  bad() { echo fail; continue; }
> 
> But then someone suggested allowing non-local break & continue was a bug,
> and the few people who considered it couldn't think of even as simple an
> example as that right there.
> 
> So it was "fixed", and now that function doesn't work. It sickens me that
> the work-around is to enable alias expansion in scripts.
> 
> *Grumble*

The idea that this would "work" is quite surprising to me.  The basic
idea of a function is that it does stuff and then returns you to the
point where you were when the function was called.

In other languages, would you expect that you might call a function,
and have that function reach upward through the call stack and manipulate
your control flow?  Some languages might have features designed for
that (Tcl's "uplevel" command comes to mind), but these are exceptions,
and experienced programmers would use such features sparingly.

What you're really looking for is the behavior of a macro, rather than
a function.  C has macros (#define), and so does bash (alias).

So, if this is the behavior you want, then do what xmb is doing.  Turn
on alias expansions, and write your flow-controlling macros as aliases.
Use functions for the things that should work normally (no control flow
modifications or parser short-circuiting), and aliases for the weird,
quirky behaviors that wouldn't normally be allowed.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]