| # Copyright (c) 2015 Wind River Systems, Inc. |
| # SPDX-License-Identifier: Apache-2.0 |
| # outputs the date and time in pre-set formats |
| # default format is: 20150114-181112 |
| # usage: timestamp [-a] [-d] [-u] [-s] [-S] |
| # where: -a changes default to: 2015-01-14-18-11-56 |
| # -d changes default to: 20150114 |
| # -u changes default to: 20150114_181201 |
| # -s changes default to: 20150114-1812.04 |
| # -S changes default to: 20150114-1812 |
| # Some switches can be mixed and matched, eg. -Sa gives 2015-01-14-18-13 |
| printf "usage: %s [-a] [-d] [-u] [-s] [-S]\n" $exe_name >&2 |
| declare -r optstr="adusSh" |
| while getopts ${optstr} opt; do |
| u) date_time_separator="_" ;; |
| s) seconds_separator="." ;; |
| if [ x${all_separated} == x1 ]; then |
| if [ x${date_only} == x1 ]; then |
| if [ x${no_seconds} == x1 ]; then |
| output_date=${date_format}${date_time_separator} |
| output_time=${time_format}${seconds_separator}${seconds_format} |
| output=$(date +${output_date}${output_time}) |