Menu

Main Menu
Talk Get Daily Search

Member's Online

    User Name
    Password

    Help - Bash script - SOLVED you can close this thread ;) a new package is coming for us

    Reply
    Page 2 of 2 | Prev |   1   2 |
    santiago | # 11 | 2011-11-20, 13:07 | Report

    right like this ? i attached the file

    i can use this to compare

    check='cat /home/user/.profiled/current'
    if [ $profilo = $check ]: then
    ......


    i did a long work i could cut the way and the time

    Edit | Forward | Quote | Quick Reply | Thanks

    Last edited by santiago; 2011-11-20 at 13:50.

     
    santiago | # 12 | 2011-11-20, 14:07 | Report

    ok maybe the script works, how can i compare functions with if then else?

    i wrote

    if 1rstcheck then
    echo "1rst check exists" else
    2ndcheck then
    echo "2nd check exists" else
    3rdcheck then
    echo "3rd check exists"


    but it doesnt work...

    Edit | Forward | Quote | Quick Reply | Thanks

     
    wnd | # 13 | 2011-11-22, 10:00 | Report

    Originally Posted by santiago View Post
    ok maybe the script works, how can i compare functions with if then else?

    i wrote

    if 1rstcheck then
    echo "1rst check exists" else
    2ndcheck then
    echo "2nd check exists" else
    3rdcheck then
    echo "3rd check exists"


    but it doesnt work...
    I'm not sure if I follow. Maybe you're after this:

    Code:
    if condition1; then
        foo1
    elif condition2; then
        foo2
    else
        foox
    fi
    Also consider writing program logic in "body" of the script, and do the magic in functions. This is what I mean:

    Code:
    #! /bin/sh
    
    set -e
    
    sub phone_is_charging() {
        lshal -u /org/freedesktop/Hal/devices/bme | grep -iq "maemo.rechargeable.charging_status = 'on'"
    }
    
    sub set_profile_and_foo() {
        foo $1
    }
    
    
    # main logic starts here
    
    if phone_is_charging; then
        set_profile_and_foo General
    else
        set_profile_and_foo Silent
    fi

    If you end up using functions, bash provides scope for variables (unlike standard Bourne shell).

    Code:
    #! /bin/bash
    
    sub foo() {
        local x="$1"
        echo $x
    }
    
    x=xyzzy
    foo bar
    echo $x
    As for backticks, please don't use them. This is 21st century.
    Code:
    foo="$(cat "$filename")"

    And finally, you may want to proect your script against unset variables.

    Code:
    test "$variable" = "yes"
    test "x$variable" = "xyes"  # if you're paranoid

    Edit | Forward | Quote | Quick Reply | Thanks

    Last edited by wnd; 2011-11-22 at 10:02. Reason: Backticks
    The Following User Says Thank You to wnd For This Useful Post:
    reinob

     
    Page 2 of 2 | Prev |   1   2 |
vBulletin® Version 3.8.8
Normal Logout