[Tcsh] tcsh Does Not Fully Recognize 'end' In an Alias

Neil R. Ormos ormos-ts23 at ormos.org
Sat Feb 4 20:18:10 UTC 2023


Christos Zoulas wrote:
> Neil R. Ormos wrote:

>> Tcsh does not appear to fully recognize the
>> 'end' of a 'foreach' loop in an alias.

>> Consider the alias zzzz, listed below, in which
>> there are three successive 'end' statements,
>> with only a single matching 'foreach'
>> statement.  When the alias is run, I would
>> expect tcsh to emit the error message

>> "end: Not in while/foreach."

>> for each of the second and third 'end'
>> statements.  However, tcsh does not complain
>> about the extra 'end's.

>> Then, after the alias finishes running, I would
>> expect tcsh to emit the same error message when
>> the first 'end' is typed as input to the shell.
>> However, tcsh does not complain about the first
>> 'end'.  The expected error message is emitted
>> only after a second 'end' is typed.

>> I don't how significant this behavior is.  When
>> using tcsh 6.20.00, I have noticed that history
>> list editing sometimes seems to become
>> confused--in that expected history items do not
>> appear when using ^p and ^n (default
>> bindings)--after the alias completes but before
>> the first 'end' is typed.  I haven't found a
>> way to reproduce that.

> This is a well-known limitation of *csh. The
> "parser" is not a LARL 1 grammar parser like one
> would expect, but just a hacky token parser that
> recognizes keywords at the beginning of the
> line, keeping minimal state. If you one is going
> to re-write it, might as well rewrite the whole
> shell :-)

Christos:

Thank you for your reply.

I'm not sure to what you are referring by "This is a well-known limitation..." --

  (a) the failure of tcsh to complain about the second 'end' in the alias?  or 

  (b) the disruption of the history list?

Also, if I place the original code in a regular file and 'source' it, the problem does not occur.  When the code is run via 'source', tcsh does complain about the second 'end' and does not disrupt the history list.

Why does the problem occur when running an alias but not when running the same code from file using 'source'?  Is there a different parser used for aliases?

Did I miss something in the man page that I should have understood as a warning about limitations in aliases?

Thanks.

--Neil Ormos


More information about the Tcsh mailing list