Find the answer to your Linux question:
Results 1 to 4 of 4
I have a problem with command line .sh scripting. I can not rewrite this in any other language, but I need to do a check when the script kicks off ...
  1. #1
    Just Joined!
    Join Date
    Feb 2009
    Posts
    1

    Command line date

    I have a problem with command line .sh scripting. I can not rewrite this in any other language, but I need to do a check when the script kicks off to see if the date is entered on the command line and if not, use yesterday. Here is what I have so far:

    if [ $# -eq 0 ]; then
    TODAY=`/usr/local/bin/cprevdate -f %m/%d/%Y`;
    echo "$# is zero "
    else
    TODAY= $1
    echo $1
    fi
    print "Today is $TODAY ";

    exit;
    I can do this in any other language, but I have never used .sh for this type of command. Please please someone, tell me what I can do to fix this!

  2. #2
    Linux Guru
    Join Date
    Nov 2007
    Posts
    1,695
    Google > calculate date linux

    Code:
    datecalc -a 1960 12 31 - 1

  3. #3
    Linux User
    Join Date
    May 2008
    Location
    NYC, moved from KS & MO
    Posts
    251
    Quick solution:
    Code:
    #!/bin/bash
    [ $# -eq 0 ] && TODAY=`date -d "yesterday" "+%m/%d/%Y"` || TODAY=$1
    echo "Today is $TODAY"
    Slow but better solution:
    man date

  4. #4
    Linux Guru
    Join Date
    Nov 2007
    Posts
    1,695
    Quote Originally Posted by secondmouse View Post
    Quick solution:
    Code:
    #!/bin/bash
    [ $# -eq 0 ] && TODAY=`date -d "yesterday" "+%m/%d/%Y"` || TODAY=$1
    echo "Today is $TODAY"
    Slow but better solution:
    man date
    Nice.

    And => LinuxForums Search

Posting Permissions

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