I'm trying to write a script which captures all the available WiFi SSIDs in my area, then puts them into an array 'a'. I don't get an error, however, when I print the size of my array at the end of the script I get 0. I'm sure I've got my array syntax wrong, but cannot figure out what to change.
0 "NETGEAR03"
1 "Scott_Guest"
2 "Spyglass 2"
3 "TELUS0527"
4 "TELUS5D4C"
5 "wino911"
0
Code:
#!/bin/bash
a=()
n=0
sudo iwlist wlan0 scan |grep ESSID |grep -v '""' |sed 's/ESSID://' |sort |uniq |while read line; do
echo "$n $line"
a[$n]="$line"
n=$((n+1))
done
echo
echo ${#a[@]}
0 "NETGEAR03"
1 "Scott_Guest"
2 "Spyglass 2"
3 "TELUS0527"
4 "TELUS5D4C"
5 "wino911"
0