0

I want to modify an array cell, which I can do when I know the cell as a number. However here my cell position is given by $i.

pomme[`${i}`]=""

I tried without the `` and it doesn't work either?

How am I suppose to do it?

3
  • 2
    pomme[$i]="" should work fine.. Commented Jun 22, 2015 at 22:42
  • Don't get print the array content like this: echo $pomme[$i], instead use echo ${pomme[$i]}. I guess that's why you think the value isn't updated. Commented Jun 22, 2015 at 22:44
  • 2
    unset pomme[$i] if you are simply clearing, otherwise pomme[$i]=("") If you are having issue, check the value of your $i. Commented Jun 22, 2015 at 22:46

1 Answer 1

1

You don't need the quotes. Just use ${i}, or even $i:

pomme[${i}]=""

Or

pomme[$i]=""
Sign up to request clarification or add additional context in comments.

1 Comment

In bash, you don't need the $ either for indexed arrays, a[i] will do (treated like ((...)) )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.