Bash Script if statement

Discussion in 'Mac Programming' started by jrock2004, Feb 11, 2011.

  1. jrock2004 macrumors 6502

    Joined:
    May 4, 2008
    Location:
    PA
    #1
    The first part of the if statement is always coming true and it should not. If I run the wirelessStatus command in the terminal nothing comes up since wireless is enabled. What am I missing here? Thanks

    Code:
    wirelessSsid=`/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I | grep -w 'SSID' | awk '{print $2}'`
    wirelessStatus=`/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I | grep -w 'AirPort' | awk '{print $2}'`
    statusText='Off'
    
    if [ $wirelessStatus=$statusText ]; then
        echo "Wireless SSID: Disabled"
    else
        echo Wireless SSID: $wirelessSsid
    fi
    
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    Try

    Code:
    if [ "$wirelessStatus" = "$statusText" ]; then
    
    This seems to work when I do it:
    Code:
    bash-3.2$ test1=`/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I | grep -w 'AirPort' | awk '{print $2}'`
    bash-3.2$ echo $test1
    
    bash-3.2$ if [ "$test1" = "$test2" ]; then echo "OK"; fi
    bash-3.2$ test1=`/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I | grep -w 'AirPort' | awk '{print $2}'`
    bash-3.2$ echo $test1
    Off
    bash-3.2$ if [ "$test1" = "$test2" ]; then echo "OK"; fi
    OK
    
     
  3. jrock2004 thread starter macrumors 6502

    Joined:
    May 4, 2008
    Location:
    PA

Share This Page