123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- exe_name=$(basename $0)
- date_format="%Y%m%d"
- time_format="%H%M"
- seconds_format="%S"
- seconds_separator=""
- date_time_separator="-"
- function usage {
- printf "usage: %s [-a] [-d] [-u] [-s] [-S]\n" $exe_name >&2
- }
- function fail {
- usage
- exit -1
- }
- function get_opts {
- declare -r optstr="adusSh"
- while getopts ${optstr} opt; do
- case ${opt} in
- a) all_separated=1 ;;
- d) date_only=1 ;;
- u) date_time_separator="_" ;;
- s) seconds_separator="." ;;
- S) no_seconds=1 ;;
- h) usage; exit 0 ;;
- *) fail ;;
- esac
- done
- }
- get_opts $@
- if [ x${all_separated} == x1 ]; then
- date_format="%Y-%m-%d"
- time_format="%H-%M"
- seconds_separator="-"
- fi
- if [ x${date_only} == x1 ]; then
- date_time_separator=""
- time_format=""
- seconds_format=""
- seconds_separator=""
- fi
- if [ x${no_seconds} == x1 ]; then
- seconds_format=""
- seconds_separator=""
- fi
- output_date=${date_format}${date_time_separator}
- output_time=${time_format}${seconds_separator}${seconds_format}
- output=$(date +${output_date}${output_time})
- echo ${output}
|