
$ factorial() ( eval let n=1 n={1..$1}*n ; echo $n )
Nov. 29, 2019, 9:06 p.m.
—
CK
Explanation
Again, using let , this takes advantage of its mathematical functions and argumentbased variable assignments to serially overwrite the last known value of n with the product of n and the next integer generated by the expansion of {1..$1} into a list of incremental numbers. However, the order in which things are expanded and substituted means that {1..$1} would fail to expand into a list without using the eval command. It provides a layer of globbing that, once the shell has substituted in the value of the parameter $1 , will allow the braces to expand.
