foo()
{
local arr=(-l largs\
-m margs\
-n nargs
)
echo "size of arr: ${#arr[@]}"
}
foo # prints 1
以上代码打印1
,但显然arr
的大小应为6
。我将代码更改为:
foo()
{
arr=(-l largs\
-m margs\
-n nargs
)
echo "size of arr: ${#arr[@]}"
}
foo # prints 6
后一版本删除了local
,并打印出正确答案。所以为什么?当地有关系吗?
PS:GNU bash,版本3.00.15(1)-release(x86_64-redhat-linux-gnu)。