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 4077268
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T17:31:45+00:00 2026-05-20T17:31:45+00:00

I am writing a bash script that needs to print the date of the

  • 0

I am writing a bash script that needs to print the date of the last working day. So for example if the script is run on a Monday, it will print the date for last Friday.

I found that this prints yesterdays date:

date -d '1 day ago' +'%Y/%m/%d'

I also know that I can get the day of the week by using this statement

date +%w

I want to combine these two statements in order to have a little helper script that prints the required date. The logic goes something like this (note: its Pseudo code – I’ve never written a bash script)

DAY_OF_WEEK = `date +%w`
if (%DAY_OF_WEEK == 1)
   LOOK_BACK = 3
elif   
   LOOK_BACK = 1
fi

echo `date -d '%LOOK_BACK day ago' +'%Y/%m/%d'`

Can someone help by correcting the pseudo code above?

(I am running on Ubuntu 10.0.4)

  • 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-05-20T17:31:45+00:00Added an answer on May 20, 2026 at 5:31 pm

    You were so close:

    day_or_week=`date +%w`
    if [ $day_or_week == 1 ] ; then
      look_back=3
    else
      look_back=1
    fi
    
    date -d "$look_back day ago" +'%Y/%m/%d'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a bash script that needs to delete old files. It's currently implemented
I'm writing a bash script that needs to parse html that includes special characters
I'm writing a bash script that needs to loop over the arguments passed into
I'm writing a bash script that needs to sudo multiple commands. I can do
I'm writing a script right now in Bash that will execute two SQL queries
I'm working on an audio encoder cgi script that utilises libmp3lame. I'm writing in
I'm writing a bash script to get some podcasts. The problem is that some
I am writing a bash script (for apt-get based OS's) that automates the installations
I've got a java code that is writing a Linux bash script out, then
I am writing a bash script to deal with some installations in an automated

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.