Shell _linux The shell based on the date, month, and week of the Year code

Source: Internet
Author: User

Known three time variables:
time1= "Fri Aug 23 11:35:21"
Time2= "Mon Sep 2 16:18:09"
Time3= "Tue Sep 3 16:06:33"
Given that these three times can be determined to occur in 2011-2013, how quickly to determine what year it is?

Want to output:
time1= "2013/8/23 11:35:21"
time2= "2013/9/2 16:18:09"
time3= "2013/9/3 16:06:33"

#!/bin/bash
time1= "Fri Aug 11:35:21" time2= "Mon
Sep 2 16:18:09" time3= "
Tue Sep 3 16:06:33"
time4= " Sun Dec 2 16:06:34 "for
((i=1;i<=4;i++)), Do for
  ((j=2011;j<=2013;j++)), do
    str=$ (eval echo \ $time $i)
    week_day=$ (date-d "${str:0:10} $j ${str:10}" "+%a")
    if ["${str:0:3}" = = $WEEK _day]; then
      echo time$i=\ "$ ( Date-d "${str:0:10} $j ${str:10}" "+%y/%m/%d%T") \ "
      # break
    fi
  done

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.