Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.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
Shell bash脚本中的Perl哈希等价物?_Shell_Hash - Fatal编程技术网

Shell bash脚本中的Perl哈希等价物?

Shell bash脚本中的Perl哈希等价物?,shell,hash,Shell,Hash,可能重复: bash中的Perl哈希等价物? 请让我知道 下面的代码在KornShell中工作得很好,但在bash[3.2版本]中没有,排版错误 #!/bin/ksh typeset -A newmap name="mandar" id="111515" newmap["name"]=$name newmap["id"]=$id echo "${newmap["id"]}" 如果您正在运行bash4或更高版本,请使用declare-A而不是typeset-A。我对它进行了测试,结果证

可能重复:

bash中的Perl哈希等价物? 请让我知道


下面的代码在KornShell中工作得很好,但在bash[3.2版本]中没有,排版错误

#!/bin/ksh 
typeset -A newmap 
name="mandar"
id="111515" 
newmap["name"]=$name
newmap["id"]=$id 
echo "${newmap["id"]}"

如果您正在运行bash4或更高版本,请使用
declare-A
而不是
typeset-A
。我对它进行了测试,结果证明它是正确的

或者,您可以测试bash并创建一个别名,这样您就可以不经修改(可能)运行脚本的其余部分:


下面的代码在KornShell中工作得很好,但在bash[3.2版本]中没有,排版错误<代码>#/bin/ksh typeset-A newmap name=“mandar”id=“111515”newmap[“name”]=$name newmap[“id”]=$id echo“${newmap[“id”]}”@mandy:你说得对,我忘了说这在Bash 4和更高版本上有效。我的是Bash4.2。
alias typeset=declare