Sample Header Ad - 728x90

How to define a recursive alias in csh (intentionally!)

1 vote
1 answer
54 views
It is known that attempting to invoke a custom alias inside itself (be it directly; or indirectly via intermediate aliases that call each other) would cause an "**Alias loop.**" error, and rightfully so. However, I would like to write a recursive csh alias, as I intend to include a base case to the recursion, so in my use case it is not an infinite loop. Here's a simplified example:
alias countdown 'if ( \!* > 0 ) then; echo \!*; countdown expr \!* - 1; endif;'
The expected output from this alias, for example with input 3, should be:
$ countdown 3
3
2
1
0
Attempting to define such an alias leads to the aforementioned "**Alias loop.**" error on csh. How can I achieve this functionality correctly? I tried using a while loop in the alias instead of recursion, but [it doesn't seem to be supported in csh](https://stackoverflow.com/a/61298726/10679420) , and [other workarounds for this alias loop issue](https://unix.stackexchange.com/q/28704/459071) are not applicable since I do not have a built-in counterpart to invoke.
Asked by Vadrif Draco (111 rep)
May 11, 2025, 01:05 PM
Last activity: Jun 2, 2025, 06:50 AM