Array in Bash Not Found
Posted
by Waffle
on Stack Overflow
See other posts from Stack Overflow
or by Waffle
Published on 2010-05-06T04:14:31Z
Indexed on
2010/05/06
4:18 UTC
Read the original article
Hit count: 246
I am trying to declare an array in bash, but when the code is run it says it cannot find the array. I have tried to write out the declaration of the array in several different ways, but it seems no matter how I try to declare it I cannot get it to work. I originally tried to declare it as such:
candidate[1]= 0
candidate[2]= 0
candidate[3]= 0
The error messages that are returned are:
votecalculation.sh: 13: candidate[1]=: not found
votecalculation.sh: 14: candidate[2]=: not found
votecalculation.sh: 15: candidate[3]=: not found
After this I tried another solution I found online:
ARRAY=( 'can1' 'can2' 'can3' )
When that is used it returns this error:
votecalculation.sh: 12: Syntax error: "(" unexpected
I am new to Bash and am getting really confused about arrays. Is there some specific way I need to declare an array or am I just going about it completely wrong?
© Stack Overflow or respective owner