Getting number of parameters in FUNCNAME

Viewed 41

Why does Snippet A

echo "params are ${FUNCNAME[@]}; param count is ${#FUNCNAME[@]}"

return

params are main; param count is 0

But Snippet B

_foo(){
    echo "params are ${FUNCNAME[@]}; param count is ${#FUNCNAME[@]}"
}

echo $(_foo)

return

params are _foo main; param count is 2

For Snippet A, shouldn't param count be 1, instead of 0?

1 Answers

This is a bug. According to bash manual:

This variable exists only when a shell function is executing.

And see Chet's comment regarding this in "bug-bash" mailing list.

Related