echo "All Index: ${NAME[*]}"
equals to echo "All Index: ${NAME[0]} ${NAME[1]} ${NAME[2]} ${NAME[3]} ${NAME[4]}"
echo "All Index: ${NAME[@]}"
equals to echo "All Index: ${NAME[0]}" "${NAME[1]}" "${NAME[2]}" "${NAME[3]}" "${NAME[4]}"
if the first character of IFS
variable is a space (default)
You can see the execution result in copy.sh.
The default value of IFS
variable is $' \t\n'
.
${array[*]}
and $*
output strings splited by the first character of IFS
variable.
It is also possible to change the character to split.
NAME[0]=Deepak
NAME[1]=Renuka
NAME[2]=Joe
NAME[3]=Alex
NAME[4]=Amir
IFS=:
echo "All Index: ${NAME[*]}"
Output: All Index: Deepak:Renuka:Joe:Alex:Amir
IFS=
echo "All Index: ${NAME[*]}"
Output: All Index: DeepakRenukaJoeAlexAmir
IFS=$', \t\n'
echo "All Index: ${NAME[*]}"
Output: All Index: Deepak,Renuka,Joe,Alex,Amir