Bash - arithmetic in array index

天涯浪子 提交于 2019-12-24 14:36:07

问题


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

回答1:


Almost there.

arr[(($x+1))]="hi"


来源:https://stackoverflow.com/questions/20762751/bash-arithmetic-in-array-index

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!