Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays 无法将函数参数分配给`Zsh中的局部数组变量`_Arrays_Linux_Shell_Unix_Zsh - Fatal编程技术网

Arrays 无法将函数参数分配给`Zsh中的局部数组变量`

Arrays 无法将函数参数分配给`Zsh中的局部数组变量`,arrays,linux,shell,unix,zsh,Arrays,Linux,Shell,Unix,Zsh,我只是尝试将函数的参数指定为局部数组变量,我尝试了 $test_print(){local foo=( "${@:1}" ); echo $foo[*]}; test_print a b c 我得到 但是如果我删除local关键字 $test_print(){foo=( "${@:1}" ); echo $foo[*]}; test_print a b c 这是工作 a b c 这里有什么问题?如何将数组保持为局部变量 其他信息 我在bashshell上尝试了这个方法,它可以作为local

我只是尝试将函数的参数指定为局部数组变量,我尝试了

$test_print(){local foo=( "${@:1}" ); echo $foo[*]}; test_print a b c
我得到

但是如果我删除
local
关键字

$test_print(){foo=( "${@:1}" ); echo $foo[*]}; test_print a b c
这是工作

a b c
这里有什么问题?如何将数组保持为局部变量

其他信息


我在
bash
shell上尝试了这个方法,它可以作为
local
global
变量使用。

为了进行想要的赋值,必须将
foo
的声明和值的赋值分为两个命令:

test_print(){local foo; foo=( "${@:1}" ); echo $foo[*]}; test_print a b c

根据
本地
的行为类似于
排版

**本地[{+|-}AEFHUahlprtux][-LRZi[n]][name[=value]]

与typeset相同,只是不允许使用选项-g和-f。在这种情况下,-x选项不强制使用-g,即导出的变量将是函数的局部变量

排版
的段落中,它说:

请注意,数组目前不能在排版表达式中赋值,只能在标量和整数中赋值

请注意,
“$@”
“${:1}”
是相同的,以保持
$
和位置参数
$1
$2
等之间的对应关系。
${:0}
顺便说一句,在扩展开始时将包括
$0
。这使得
$@
不同于数组<代码>a=(1 2 3);echo${a[@]:1}生成23,而不是123。
test_print(){local foo; foo=( "${@:1}" ); echo $foo[*]}; test_print a b c