Article 6KQEX Facing a problem because of the "Spaces" in networks names

Facing a problem because of the "Spaces" in networks names

by
1krdk
from LinuxQuestions.org on (#6KQEX)
Hello everyone!
i have a thin client device with armbian cli OS, and I've created a script that would "using nmcli" list a numerated list of the names of the available networks and select one of them by it's number like:
Available networks:
1. my_home
2. some_network
3. my
4. wifi
"the problem is in listing network 3,4 in different lines"
when clicking on 1, it would ask for the password of "my_home",then type it's password and you are connected..
the problem is if i want to connect to "my wifi" network it is seeing it as if it's a different netowkrs because of the space between my and wifi in the name

here is the functions i'm using:
Code:connect_network() {
local networks=( $(nmcli -f SSID device wifi list | awk 'NR>1{print NR-1".", $0}') )
if [ ${#networks[@]} -eq 0 ]; then
echo "No available networks found. Exiting."
exit 1
fi

while true; do
echo "Available networks:"
for (( i=0; i<${#networks[@]}; i++ )); do
echo "$((i+1)). ${networks[$i]}"
donewhen the network name contains a space, I'm unsure how to properly format it for connection because nmcli uses my\ wifi when there is a spaces

Could someone please provide me with a solution or workaround for connecting to the Wi-Fi networks with spaces in their names within the script? Any assistance would be greatly appreciated.

Thank you!
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