#885394 In an Alias, tcsh Does Not Correctly Run a Nested Alias in the Then and Else parts of an If/Then/Else/Endif Statement

Package:
tcsh
Source:
tcsh
Description:
TENEX C Shell, an enhanced version of Berkeley csh
Submitter:
"Neil R. Ormos"
Date:
2017-12-26 17:24:04 UTC
Severity:
normal
#885394#5
Date:
2017-12-26 17:21:58 UTC
From:
To:
Dear Maintainer,

Expansion of nested aliases usually works as I
would expect...

.... but not when the nested alias is called from
within an if/then/else/endif statement.

The problem is demonstrated in the following
transcript between the "####" lines.  Lines
beginning with "##" are my comments added later,
and were not typed in to the shell.

I have observed the same behavior the versions
listed below on Debian systems and also in an old
Sun Solaris environment to which I have access:

  tcsh 6.12.00 on Sun Solaris;
  tcsh 6.17.02 on Squeeze;
  tcsh 6.18.01 on Wheezy;
  tcsh 6.18.01 on Jessie; and
  tcsh 6.20.00 (compiled by me) on Jessie.

I am reporting here because the published upstream
reporting channel appears to be out of service.

Best regards,

## Define kkk, a short alias containing only a
## trivial echo statement.
echo Trivial echo statement in an alias.

## Run kkk.
Trivial echo statement in an alias.

## Output was what I expected.

## Run the following series of commands including
## an if/then/else statement.  I expect only the
## else part to be executed.  The else part
## includes a plain echo statement and an
## invocation of kkk alias, which I expect to be
## be expanded as above:
##
## set xxx=0
## if ( $xxx ) then
##   echo "The then part."
##   kkk a
## else
##   echo "The else part."
##   kkk b
## endif
if?   echo "The then part."
if?   kkk a
if? else
The else part.
Trivial echo statement in an alias. b

## Output was what I expected. Both the plain echo
## statement and the kkk alias ran, and no error
## message was printed.

## Define jjj, an alias intended to be equivalent
## to the prior series of commands.
? if ( $xxx ) then\
?   echo "The then part."\
?   kkk a\
? else\
?   echo "The else part."\
?   kkk b\
? endif'
set xxx=0
if ( $xxx ) then
  echo "The then part."
  kkk a
else
  echo "The else part."
  kkk b
endif

## Run jjj. Again, I expect only the else part to be executed.
The else part.
endif: Too many arguments.

## The plain echo statement worked correctly.
## However, the invocation of alias kkk did not
## work correctly, and tcsh printed the error
## message "endif: Too many arguments."
exit

Script done on Tue Dec 26 10:52:02 2017

############################################################