It means that networksetup
does not behave very well and returns 0
regardless the error message. This code will print the return code 0
in both cases:
networksetup -removepreferredwirelessnetwork en1 ; echo $?
The solution is to parse the output:
networksetup -removepreferredwirelessnetwork en1 2>&1 | grep -q "was not found in the preferred networks list" && say "Network deleted"