On Wed, Oct 03, 2012 at 05:07:16AM +0000, Yuxiang Cao wrote: > Hi, > After second thought, I carefully read the bash manual page and find this > information. Functions may be recursive. The FUNCNEST variable may be used to > limit the depth of the function call stack and restrict the number of > function invocations. By default, no limit is placed on the number of > recursive calls. So in my example, what I think I can do is to limit the > times of recursive calls. So I simply export FUNCNEST variable as " export > FUNCNEST=500", however, it doesn't work. That could be a bug for bash, right?
It would help if you show what you're doing and what the result is. It seems to work correctly here: imadev:~$ bash-4.2.28 -c 'FUNCNEST=100; a() { echo "$1"; a $(($1+1)); }; a 1' 2>&1 | tail 92 93 94 95 96 97 98 99 100 bash-4.2.28: a: maximum function nesting level exceeded (100) Without the FUNCNEST, it runs for several seconds, and then: imadev:~$ bash-4.2.28 -c 'a() { echo "$1"; a $(($1+1)); }; a 1' 2>&1 | tail Pid 4466 received a SIGSEGV for stack growth failure. Possible causes: insufficient memory or swap space, or stack size exceeded maxssiz. 6534 6535 6536 6537 6538 6539 6540 6541 6542 6543 imadev:~$ ls -l core -rw------- 1 wooledg pgmr 19908052 Oct 3 08:38 core imadev:~$ file core core: core file from 'bash-4.2.28' - received SIGSEGV (Happy, Linda?)