Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8876389
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:12:11+00:00 2026-06-14T19:12:11+00:00

This question is related to the thread here: Today's date, minus X days in

  • 0

This question is related to the thread here:

Today's date, minus X days in shell script

But because I’m now manipulating the variable, I started another thread.

As described above, I need to get today’s date minus 200 days, with the Year, Month, and Day in separate variables (in this question I’ll use 200, though in the other it’s 222). However, I need to represent January as 0, February as 1 (or 01), March as 2 (or 02), etc… I tried this:

MONTHS200=$(date -j -v-200d -v-1m +"%m")
if ${MONTHS200}=01; then 
${MONTH200}=0
else ${MONTHS200}=${MONTH200}
fi

But I get the error ./update_newdateformat.sh: line 20: 12=01: command not found ./update_newdateformat.sh: line 23: 12=: command not found The -v-1m works for all months except January, because it goes to 12, instead of 0

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T19:12:12+00:00Added an answer on June 14, 2026 at 7:12 pm

    Here’s how to shift all the month number down by 1 n your script:

    MONTHS200=$(date -j -v-320d +"%m")
    
    # Remove leading zero if there is one, so it doesn't cause problems later
    MONTHS200=${MONTHS200#0}
    
    MONTHS200=$((MONTHS200-1))
    

    Here is how to use if and = (assignment) syntax in shell:

    if [[ "${MONTHS200}" == "01" ]]; then
        MONTHS200="0"
    else
        MONTHS200=${AnotherVariable}
    fi
    

    Note that for numerical comparisons, you need to use:

    • -eq instead of ==
    • -ne instead of !=
    • -lt instead of <
    • -le instead of <=
    • -gt instead of >
    • -ge instead of >=

    For example:

     if [[ "${MONTHS200}" -eq 1 ]]; then 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is related to a question I asked here: Thread Locking in Ruby (use
This question is related to another thread, you can read here: Forms authentication with
My question is related to this thread. Here is the code #include <stdio.h> int
not sure if this question should be here or in serverfault, but it's java-related
This question is related to the one I asked here . I'm trying to
This is related to my previous question , but it seems I have another
This question is related to following thread. Prism RegionAdapter - Removing then Adding View
This question is picking up from the following thread on the (now read-only) OpenRasta
This is related to a previous question . What I'm trying to understand now
This question is related to this previous thread . I followed Tomas's suggestion using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.