Menu

Main Menu
Talk Get Daily Search

Member's Online

    User Name
    Password

    [Linux bash] Why is this not working?

    Reply
    Page 1 of 3 | 1   2     3   | Next
    eitama | # 1 | 2010-03-11, 16:23 | Report

    I've been at this for 3 hours now.
    It's not wrorking.

    Code:
    #!/bin/sh
    
    #my=`/sbin/ifconfig usb0`
    my="abcd"
    
    if [ $my == "*bc*" ]
    then
            echo "Ok"
    else
            echo "Not ok"
    fi
    This prints "Not ok" when i would expect it to print Ok.

    I ran this on my phone using putty.

    On the other hand :

    this works :

    Code:
    #!/bin/sh
    
    #my=`/sbin/ifconfig usb0`
    my="abcd"
    
    if [ $my == "abcd" ]
    then
            echo "Ok"
    else
            echo "Not ok"
    fi
    Please help

    Edit | Forward | Quote | Quick Reply | Thanks

     
    gobuki | # 2 | 2010-03-11, 16:31 | Report

    I didn't know that * is working like that with strings. Is it? It's expanded to filesystem objects names in bash.

    If you are sure this should work. How about using #!/bin/bash? :-)

    Edit | Forward | Quote | Quick Reply | Thanks

     
    eitama | # 3 | 2010-03-11, 16:41 | Report

    As far as I know, glob works with == yes,

    But, there is no bash on the N900, busybox....

    Edit | Forward | Quote | Quick Reply | Thanks

     
    fatalsaint | # 4 | 2010-03-11, 16:41 | Report

    Code:
    #!/bin/sh
    
    #my=`/sbin/ifconfig usb0`
    my="abcd"
    
    if [ "$my" == *bc* ]
    then
            echo "Ok"
    else
            echo "Not ok"
    fi
    Maybe?

    Edit | Forward | Quote | Quick Reply | Thanks

     
    eitama | # 5 | 2010-03-11, 16:45 | Report

    Originally Posted by fatalsaint View Post
    Code:
    #!/bin/sh
    
    #my=`/sbin/ifconfig usb0`
    my="abcd"
    
    if [ "$my" == *bc* ]
    then
            echo "Ok"
    else
            echo "Not ok"
    fi
    Maybe?
    Doesn't matter, still won't work.
    The thing that is not working is the * (asterisks).

    What I am ultimately trying to do is check if usb0 is RUNNING.

    Edit | Forward | Quote | Quick Reply | Thanks

     
    JosefA | # 6 | 2010-03-11, 16:46 | Report

    PHP Code:
    #!/bin/bash

    my="abcd"

    if [[ $my = *bc* ]]
    then
            
    echo "Ok"
    else
            echo 
    "Not ok"
    fi 

    Edit | Forward | Quote | Quick Reply | Thanks

     
    eitama | # 7 | 2010-03-11, 16:48 | Report

    Originally Posted by JosefA View Post
    PHP Code:
    #!/bin/bash

    my="abcd"

    if [[ $my = *bc* ]]
    then
            
    echo "Ok"
    else
            echo 
    "Not ok"
    fi 
    I don't have BASH on my N900.

    Edit | Forward | Quote | Quick Reply | Thanks

     
    kopele | # 8 | 2010-03-11, 16:48 | Report

    Comparing strings like this is a form of regex which requires you use double square brackets around it: if [[ ]]

    Edit | Forward | Quote | Quick Reply | Thanks
    The Following 2 Users Say Thank You to kopele For This Useful Post:
    gobuki, HoX

     
    JosefA | # 9 | 2010-03-11, 16:51 | Report

    The point is, look at the difference between that and your code. The point isn't "do you have bash on your N900". I don't either.

    Edit | Forward | Quote | Quick Reply | Thanks

     
    fatalsaint | # 10 | 2010-03-11, 16:53 | Report

    Oops.. I forgot the double brackets.

    I knew the lack of quotes on the *bc* though...

    Edit | Forward | Quote | Quick Reply | Thanks
    The Following User Says Thank You to fatalsaint For This Useful Post:
    KristianW

     
    Page 1 of 3 | 1   2     3   | Next
vBulletin® Version 3.8.8
Normal Logout