#!/bin/bash
#
mac=$(sudo networksetup -getinfo Wi-Fi | grep Wi-Fi | awk '{print $NF}')
gh=$(sudo security find-generic-password -l "${ssid}" | grep "acct" | grep blob | sed 's/"//g' | cut -d "=" -f 2)
pwd=$(sudo security find-generic-password -l "${ssid}" -w)
pwd=$(echo "${pwd}" | sed 's/&/%26/g')
prefix="ok"
# 使用 Bash 的模式匹配功能来判断字符串是否以指定的子字符串开始 两个中括号表示模式匹配或者理解为正则
if [[ $str == $prefix* ]]; then # $prefix*的前后不能有双引号
echo "ok ok"
else
#清空已记住的网络
enX=$(sudo /usr/sbin/networksetup -listallhardwareports | sudo /usr/bin/awk '/Wi-Fi|AirPort/ {getline; print $NF}')
sudo networksetup -listpreferredwirelessnetworks $enX | grep -iv "Preferred networks" | xargs -I {} sudo networksetup -removepreferredwirelessnetwork $enX {}
sudo security delete-generic-password -l "$ssid"
result="${result}\n以清空已记住的网络"
fi
(/usr/bin/osascript -e "display dialog \"$result\" buttons {\"OK\"} default button \"OK\" ")