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

Christos Zoulas christos at zoulas.com
Sat Feb 4 19:01:43 UTC 2023



> On Jan 14, 2023, at 9:32 PM, Neil R. Ormos <ormos-ts23 at ormos.org> 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 :-)

Best,

christos

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 235 bytes
Desc: Message signed with OpenPGP
URL: <https://mailman.astron.com/pipermail/tcsh/attachments/20230204/675cdf1e/attachment.asc>


More information about the Tcsh mailing list