Article 5JG8W BASH script - array problem

BASH script - array problem

by
mjscott00
from LinuxQuestions.org on (#5JG8W)
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. Sample output is right after the code segment.
Thanks!

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"

0latest?d=yIl2AUoC8zA latest?i=bEcp1gqo-0E:mOqaAjnH5oo:F7zBnMy latest?i=bEcp1gqo-0E:mOqaAjnH5oo:V_sGLiP latest?d=qj6IDK7rITs latest?i=bEcp1gqo-0E:mOqaAjnH5oo:gIN9vFwbEcp1gqo-0E
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments