Results 1 to 7 of 7

Thread: Bash Files

  1. #1
    Join Date
    Sep 2012
    Beans
    19

    Bash Files

    I would like to make thisfunction work though ... actually i'm not able to fix the problem :/

    ms="`date +%m`"
    if ["11" == "11"]; then
    echo "$ms"
    else
    echo "not working"
    fi

  2. #2
    Join Date
    Feb 2009
    Location
    Dallas, TX
    Beans
    6,590
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Bash Files

    Hi netwo.

    A few tips about the syntax:

    Backticks are deprecated, prefer this syntax:
    Code:
    ms="$(date +%m)"
    The 'if' construction needs space between its tokens:
    Code:
    if [ "11" == "11" ]; then ...
    In terms of what you need to do, and if it is doing it right, there's no much information.

    What are you trying to do?

    Regards.

  3. #3
    Join Date
    Sep 2012
    Beans
    19

    Re: Bash Files

    If the month is november then do a certain cOmnand line

  4. #4
    Join Date
    Feb 2009
    Location
    Dallas, TX
    Beans
    6,590
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Bash Files

    Then you need to compare the results of date to 11:

    For instance comparing numbers
    Code:
    ms=$(date +%m)
    
    if [ $ms -eq 11 ]; then
        echo "doing certain command."
    else
        echo "doing nothing."
    fi
    Or comparing strings:
    Code:
    ms="$(date +%m)"
    
    if [ "$ms" == "11" ]; then
        echo "doing certain command."
    else
        echo "doing nothing."
    fi
    Let us know how it goes.
    Regards.

  5. #5
    Join Date
    Sep 2012
    Beans
    19

    Re: Bash Files

    Actually thank you very much for the help to get this script work. i wanted to have some good tutorial if you have some please.

  6. #6
    Join Date
    Feb 2009
    Location
    Dallas, TX
    Beans
    6,590
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Bash Files

    Here are a couple of resources:

    Regards.

  7. #7
    Join Date
    May 2009
    Location
    Fareham, UK
    Beans
    Hidden!
    Distro
    Xubuntu 13.04 Raring Ringtail

    Re: Bash Files

    Im always referring to this guide http://tldp.org/LDP/abs/html/ for bash syntax
    Catch me on Freenode - imark

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •