I have this script -
nmapout=`sudo nmap -sP 10.0.0.0/24` names=`echo "$nmapout" | grep "MAC" | grep -o '(.\+)'` echo "$names"
now the $names variable contains strings separated by newlines -
>_ (Netgear) (Hon Hai Precision Ind. Co.) (Apple)
I tried to do array conversion with subscript approach -
names=(${names//\\n/ }) echo "${names[@]}"
But the problem is that I cannot access them by indexing (ie ${names[$i] etc.) if I run this loop -
for (( i=0; i<${#names[@]}; i++ )) do echo "$i: ${names[$i]" # do some processing with ${names[$i]} done
I get this conclusion -
>_ 0: (Netgear) 1: (Hon 2: Hai
but I want -
>_ 0: (Netgear) 1: (Hon Hai Precision Ind. Co.) 2: (Apple)
I could not figure out how to do this, please note that there are spaces in the second line.
Any idea?
arrays bash newline
ramgorur
source share