array + = value在ksh中不起作用? [英] array+=value not work in ksh?

查看:105
本文介绍了array + = value在ksh中不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在某处读到ksh的数组支持+=来添加新元素,但是我尝试了一下,但它不起作用:

I read somewhere that ksh's array supports += to append new elements, but I tried it and it doesn't work:

[ksh] # arr=(a b c d)
[ksh] # arr+=e
[ksh] # echo ${arr[*]}
ae b c d
[ksh] #

为什么arr[0]变为ae?

推荐答案

要将元素添加到数组,应该像这样:

To add an element to the array, it should be like this:

arr+=(e)

通过执行arr+=e,它将添加到数组的第一个元素中.这是因为仅名称arr指向数组本身的第一个元素:

By doing arr+=e , it will add to the 1st element of the array. Its because just the name arr points to the 1st element of the array itself:

$ arr=(a b c d)
$ echo ${arr[0]}
a
$ echo $arr
a

这篇关于array + = value在ksh中不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆