What shell are you using? I'd rather think name=ENV1 assigns the string constant "ENV1" to the scalar variable name , so the 123 output is a bit surprising to me... possible that the array name has been assigned to earlier?
ENV1[0]=123 ENV1[1]=789 ENV1[2]=120 ENV2[0]=567 if [ $1 -eq 1 ] then Set -A name ${ENV1[@]} echo "${name[0]}" echo "${name[1]}" echo "${name[2]}" else name=ENV1 echo "${name[1]}" fi