/bin/datestr
Korn Shell | 69 lines | 33 code | 5 blank | 31 comment | 2 complexity | f6442f2efe9a09f509490112890e96fd MD5 | raw file
- #!/bin/env ksh
- #
- # Copyright (C) Young, Fey <fey.young@gmail.com>
- #
- # This program is free software: you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation, either version 3 of the License, or
- # (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
- #
- # SCRIPT: datestr
- # AUTHOR: Young, Fey
- # DATE: 2010-8-30
- # REV: 1.0.P
- #
- # PURPOSE: print the current datetime in specified format
- #
- # set -n # Uncomment to check syntax without execution
- #
- # set -x # Uncomment to debug
- #
- ############################# FUNCTIONS ##################################
- function usage {
- echo "Usage: datestr [option]"
- echo " -s, --short YYYY-mm-dd"
- echo " -l, --long YYYY-mm-dd HH:MM:SS"
- echo " -c, --compact YYYYmmdd"
- echo " -d, --default YYYYmmddHHMMSS"
- exit 1
- }
- ################################ MAIN ####################################
- if (( $# > 1 ))
- then
- usage
- fi
- flag='-d'
- if (( $# == 1 ))
- then
- flag=$1
- fi
- case $flag in
- '-d')
- date '+%Y%m%d%H%M%S'
- ;;
- '-s')
- date '+%Y-%m-%d'
- ;;
- '-c')
- date '+%Y%m%d'
- ;;
- '-l')
- date '+%Y-%m-%d %H:%M:%S'
- ;;
- *)
- usage
- esac
- # End of script