3025 shaares
2 results
tagged
timestamp
Ausgabe des aktuellen timestamp mit bash printf ohne $(date +…):
printf "%(%FT%T%z)T\n"
… aber nicht ganz …
~$ printf "%(%FT%T%z)T msg: %s\n" "mjggjgjh"
bash: printf: mjggjgjh: invalid number
1970-01-01T01:00:00+0100 msg:
~$ printf "%(%FT%T%z)T\n" "123456"
1970-01-02T11:17:36+0100
~$ printf "%(%FT%T%z)T msg: %s\n" "$(date +%s)" "wrether the rztj rtzhj"
2020-10-19T07:46:27+0200 msg: wrether the rztj rtzhj
man bash:
printf [-v var] format [arguments]
Write the formatted arguments to the standard output under the control of the format. The -v option
causes the output to be assigned to the variable var rather than being printed to the standard output.
The format is a character string which contains three types of objects: plain characters, which are
simply copied to standard output, character escape sequences, which are converted and copied to the
standard output, and format specifications, each of which causes printing of the next successive argu‐
ment. In addition to the standard printf(1) format specifications, printf interprets the following ex‐
tensions:
%b causes printf to expand backslash escape sequences in the corresponding argument in the same way
as echo -e.
%q causes printf to output the corresponding argument in a format that can be reused as shell in‐
put.
%(datefmt)T
causes printf to output the date-time string resulting from using datefmt as a format string for
strftime(3). The corresponding argument is an integer representing the number of seconds since
the epoch. Two special argument values may be used: -1 represents the current time, and -2 rep‐
resents the time the shell was invoked. If no argument is specified, conversion behaves as if
-1 had been given. This is an exception to the usual printf behavior.
Arguments to non-string format specifiers are treated as C constants, except that a leading plus or mi‐
nus sign is allowed, and if the leading character is a single or double quote, the value is the ASCII
value of the following character.
The format is reused as necessary to consume all of the arguments. If the format requires more argu‐
ments than are supplied, the extra format specifications behave as if a zero value or null string, as
appropriate, had been supplied. The return value is zero on success, non-zero on failure.