[英]Bash - arithmetic in array index
Say I have an array arr
and an index x
. 假设我有一个数组
arr
和一个索引x
。 How do I assign something to the array at index x+1? 如何在索引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"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.