I have the following example script and want to know what exactly is the length of an array, are this bytes, characters or what else?
#!/bin/bash
# Arrays
# @ vs. *
ape=( "Apple Banana" "Emacs Window" "Panda Bamboo Nature" )
cape=( 'Ping Pong' 'King Kong' 'King Fisher Club' 'Blurb' )
jade=( ally belly cally delly )
echo Expansion with \*
echo ${ape[*]}
echo ${cape[*]}
echo -e "${jade[*]}\n"
echo Expansion with \@
echo ${ape[@]}
echo ${cape[*]}
echo -e "${jade[@]}\n"
echo Elements with \*
echo ${#ape[*]}
echo ${#cape[*]}
echo ${#jade[*]}
echo Elements with \@
echo ${#ape[@]}
echo ${#cape[@]}
echo ${#jade[*]}
echo -e "\nLength"
echo ${#ape}
echo ${#cape}
echo ${#jade}
From the man pages I know, that the array expansion differs from * to @ if the word is double-quoted or not, but I cannot see any differences. Why do I have in both cases the same results?
The output is as follows:
Expansion with *
Apple Banana Emacs Window Panda Bamboo Nature
Ping Pong King Kong King Fisher Club Blurb
ally belly cally delly
Expansion with @
Apple Banana Emacs Window Panda Bamboo Nature
Ping Pong King Kong King Fisher Club Blurb
ally belly cally delly
Elements with *
3
4
4
Elements with @
3
4
4
Length
12
9
4