bash-3.00$ cat arr.bash #!/bin/bash declare -a myarray myarray[2]="two" myarray[5]="five" echo ${#myarray[*]} echo ${#myarray[@]} bash-3.00$ ./arr.bash 2 2 both are giving number of elements of array. So what is difference between the two?
There is no difference. They both give the number of elements in the array. The difference comes when you use the array expansion "${array[*]}" in double quotes and have IFS set to some value other than the default.
$ array=(1 2 3) $ echo "${array[*]}" 1 2 3 $ saveIFS=$IFS $ IFS="," $ echo "${array[*]}" 1,2,3 $ IFS=$saveIFS