I want to create an array in Bash which to contain all active network interfaces.
I have managed to create a for loop printing them but when I try to create the array, it just contains the last lo interface but not the other. This is my code:
#!/bin/bash
for iface in $(ifconfig | cut -d ' ' -f1| tr ':' '\n' | awk NF)
do
printf "$iface%s\n"
declare -a array_test=["$iface"]
done
for i in "${array_test[@]}"; do echo "$i"; done
And this is my output:
eno1
eno2
eno3
lo
[lo]
Also, how can I exclude the lo localhost interface from the array?