Bash-数组索引中的算术 [英] Bash - arithmetic in array index
本文介绍了Bash-数组索引中的算术的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
说我有一个数组 arr
和一个索引 x
。如何为索引x + 1的数组分配内容?我尝试以下方法来获取错误,如果其中一个正确,我想知道是哪个错误,如果不是,我做错了什么?
Say I have an array arr
and an index x
. How do I assign something to the array at index x+1? I'm getting bugs by trying the following, if one of them is correct I'd love to know which one and if not what am I doing wrong?
arr[$x+1]="hi" # Doesn't work
arr[$((x+1))]="hi" # Nope
推荐答案
几乎在那里。
arr[(($x+1))]="hi"
这篇关于Bash-数组索引中的算术的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文