Shell script arrays Shell script arrays arrays arrays

Shell script arrays


Remove the spaces:

array[$i]='sg'

Also, you should access the elements as*:

echo ${array[0]}

See e.g. http://tldp.org/LDP/abs/html/arrays.html.


* Thanks to @Mat for reminding me of this!


It should work if you had declared your variable as array, and print it properly:

declare -a arrayfor i in 0 1 2 3 4 5 6 7 8 9 do    array[$i]="sg"doneecho ${array[0]} echo ${array[1]} 

See it in action here.

HTH


there is problem with your echo statement: give ${array[0]} and ${array[1]}