Find the answer to your Linux question:
Results 1 to 3 of 3
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    [SOLVED] Subtracting years from current year


    I have a script:
    Code:
    #!/bin/bash
    THEYEAR=2011
    LASTYEAR=$(($THEYEAR - 1))
    echo $THEYEAR
    echo $LASTYEAR
    I get:

    2011
    2010

    I have another script:
    Code:
    #!/bin/bash
    THEYEAR=TZ=EST-24 date +20%y
    LASTYEAR=$(($THEYEAR - 1))
    echo $THEYEAR
    echo $LASTYEAR
    I get:

    2011

    -1

    THEYEAR is correct but then I get a line space and then a -1 for LASTYEAR.

    I can't figure out why.

  2. #2
    try this
    #!/bin/bash
    THEYEAR=`TZ=EST-24 date +20%y`
    echo "$THEYEAR the year";
    LASTYEAR=$((`echo $THEYEAR`-1))
    echo $THEYEAR
    echo $LASTYEAR

  3. #3
    Quote Originally Posted by pratapsingh View Post
    try this
    #!/bin/bash
    THEYEAR=`TZ=EST-24 date +20%y`
    echo "$THEYEAR the year";
    LASTYEAR=$((`echo $THEYEAR`-1))
    echo $THEYEAR
    echo $LASTYEAR

    Yup, this works and I see the errors of my ways. Thanks for your help pratapsingh.

    Trapper

  4. $spacer_open
    $spacer_close

Posting Permissions

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