Script Wi-Fi SSID switch if on SSID "X" I'm stuck on a script to switch a Mac to a different SSID if its already connected to a certain SSID.

What I need the script to do is:

Check what SSID the Mac Wi-Fi is using

If it is on SSID called "CompanyA" switch to SSID called "CompanyB"
If it is not on SSID called "CompanyA" do nothing.

I can get SSID currently connected to with

networksetup -getairportnetwork en0 | cut -d ":" -f2


and I can switch with

networksetup -setairportnetwork en0 "CompanyB"


But I don't know how to do the if on CompanyA then switch to CompanyB
Test ([) if the output of networksetup is the same as the string CompanyA if so then change the SSID to CompanyB.

curssid=$(networksetup -getairportnetwork en0 | cut -d ' ' -f4-)

if [ "$curssid" = CompanyA ]
then
networksetup -setairportnetwork en0 "CompanyB"
fi