[Tcsh] The parser's algorithm is interesting.

M G P tateusg at hotmail.com
Sun Nov 19 08:51:23 UTC 2023


Been playing with this Shell for some time now, and, recently, found the parser's algorithm interesting.

Tom Christiansen's complaints on flow control regard commands executed in if statements as impossible to be redirected. Except if in a sub-shell, is really impossible. Why's that triggered an interest in finding out how control structures influence redirection.

Turns out commands in if statements have their output redirected to if itself.

if ( { echo ok | grep ok } ) then
  echo ok
endif

Will always return false. I believe because is piping to if, since

if ( { echo ok > ok } ) then > ok
  echo ok
endif

redirects OK. Somehow, botches up and redirects to if. Or curly braces alone aren't meant for complex procedures. This syntax breaks nested conditions, though.

In sub-shells, however, if the output isn't redirected, it's redirected to if as well.

The form

if >& /dev/null ( { echo ok > ok } ) then
  echo ok
endif

works too, except (and shouldn't) for pipes. But this

>& /dev/null if ( { echo ok > ok } ) then
  echo ok
endif

is an error, even though is acceptable for most (if not all) commands. Without parentheses, however, works.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.astron.com/pipermail/tcsh/attachments/20231119/d4baccf9/attachment.htm>


More information about the Tcsh mailing list