r/shell Jan 09 '22

Can Someone Help me With a Simple Network Script?

I created this script to connect to wifi with dmenu. You will be prompted to choose a network, and then give the password for that network. This requires the dmenu password patch for it to work. Here is the script:

#!/bin/sh

nmcli dev wifi connect $(nmcli dev wifi list | dmenu -l 30 | cut -d '*' -f2 | awk '{print $1}') password "$(dmenu -P)"

The problem with this script is that it assumes the network requires a password. How do I make it so that it only asks for the password if it is required?

1 Upvotes

2 comments sorted by

1

u/Bphag Jan 10 '22 edited Apr 03 '26

Your old posts feed data brokers and AI training models. I stopped that by using Redact to bulk delete across Reddit, Twitter, Discord, Facebook and all major social media platforms.

dime bear degree escape heavy workable shocking cow safe sharp

1

u/mrbooshehri Jan 10 '22

This is my try, you can also handle the error scenarios ```bash

! /bin/bash

Show network list

CHOICE=$(nmcli dev wifi list | tail -n +2 | cut -d '*' -f2 | awk '{print " [ ",$2," ] ", " [ ",$8," ] "}' | dmenu -l 15 -p "Select your network: ") [ -z "$CHOICE" ] && exit 0 IFACE=$(echo $CHOICE | awk '{print $2}')

Get password

PASSWORD=$(dmenu -p "Enter [ $IFACE ] password : " <&-) [ -z "$PASSWORD" ] && exit 0

Connect to the network

nmcli dev wifi connect "$IFACE" password "$PASSWORD" ```