Find the answer to your Linux question:
Results 1 to 3 of 3
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)) ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Apr 2005
    Posts
    41

    [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
    Just Joined! pratapsingh's Avatar
    Join Date
    Feb 2009
    Posts
    82
    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
    Just Joined!
    Join Date
    Apr 2005
    Posts
    41
    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

Posting Permissions

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