array_item= (item1 item2)
Don't put spaces around the =
in assignment, it doesn't work. Also this gives me a syntax error about the parenthesis. You could get the check_: command not found
error if the array elements are unset or empty.
for (( i=0; i<${array_item[@]}; i++ ))
${array_item[@]}
expands to all elements of the array, I think you want ${#array_item[@]}
for the number of elements. If the array is empty, this should also give an error, since the other operand to the comparison will be missing.
The for (( ... )) { cmds...}
construct seems to work in Bash, but the manual only describes the usual for (( ... )) ; do ... ; done
construct.
Or just use for x in "${array_item[@]}" ; do ... done
to loop over the values of the array.
If you do need the indices while looping, it might be technically better to loop over "${!array_item[@]}"
, since the indices don't actually need to be contiguous. That works with associative arrays too.