Here is an updated script that works for macOS 26 devices, seems Apple will change the ability to get the SSID via terminal and will most likely remove it at some point.
#!/bin/bash
# Enable verbose mode for ipconfig sudo ipconfig setverbose 1
# Get the current SSID and display it for interface en0 SSID=$(ipconfig getsummary en0 | awk -F ' SSID : ' '/ SSID : / {print $2}')
# Check if SSID is found if [ -n "$SSID" ]; then echo "Connected SSID: $SSID" else echo "SSID not found or not connected." fi