sh Bash日期模块

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh Bash日期模块相关的知识,希望对你有一定的参考价值。

#!/bin/bash
# Name: Mark Henes
# Date: 10-18-2015
# Purpose: Module of date formats and commands.
###
# Different formats, functions, and loops as timestamp counters to be used as a module for parent scripts.

# Day
function d {
    date "+%d"
}
# Month
function m {
    date "+%m"
}
# Year
function Y {
    date "+%Y"
}
# Hour
function H {
    date "+%H"
}
# Minute
function M {
    date "+%M"
}
# Second
function S {
    date "+%S"
}
# Month, Day.
function md {
    date "+%m-%d"
}
# Month, Day, Year.
function mdY {
    date "+%m-%d-%Y"
}
# Month, Day, Year, Hour.
function mdYH {
    date "+%m-%d-%Y%n%H"
}
# Month, Day, Year, Hour, Minute.
function mdYHM {
    date "+%m-%d-%Y%n%H:%M"
}
# Month, Day, Year, Hour, Minute, Second.
function mdYHMS {
    date "+%m-%d-%Y%n%H:%M:%S"
}
# Text, Month, Day, Year, Hour, Minute, Second.
function mdYHMS-text {
    date "+DATE: %m-%d-%Y%nTIME: %H:%M:%S"
}
# One second counter for 10 seconds.
function one_sec_counter_for_10 {
    for i in `seq 1 10`;
    do
        sleep 1
        mdYHMS
        done  
}
# One second counter for 30 seconds.
function one_sec_counter_for_30 {
    for i in `seq 1 30`;
    do
        sleep 1
        mdYHMS
        done  
}
# One second counter for 60 seconds.
function one_sec_counter_for_60 {
    for i in `seq 1 60`;
    do
        sleep 1
        mdYHMS
        done  
}
###
# OUTPUT
###
# Uncomment hashtag to write to file. Change function to output different format.
mdYHMS # > date.txt
###
# Call this script from another script by the following usage example:
# bash date.sh
# /bin/bash /path/to/script
###
# End
exit

以上是关于sh Bash日期模块的主要内容,如果未能解决你的问题,请参考以下文章

sh Bash - 日期模块 - 作为时间戳计数器的不同格式,函数和循环,用作父脚本的模块。

sh [bash循环日期进行操作] #bash

sh Bash:日期:从日期获取工作日

sh Bash日期

sh 使用bash构建日期序列。

sh bash时间戳和/或日期