Re: A small documentation suggestion

2019-01-08 Thread Keith Thompson
Yes, you can do that, and it would be a good workaround *if*
$EPOCHREALTIME didn't already have 6 digits after the decimal point,
including any trailing zeros.

The point is that you don't have to, and I'm suggesting that the
documentation should make that clear so users can rely on it.

${EPOCHREALTIME: -6}

On Tue, Jan 8, 2019 at 2:13 AM Andreas Schwab  wrote:
>
> On Jan 07 2019, Keith Thompson  wrote:
>
> > I suggest documenting this behavior. It would be nice to be able to
> > depend on the exact format, for example that ${EPOCHREALTIME/*./}
> > is always exactly 6 digits long.
>
> ms=${EPOCHREALTIME/*./}00
> ms=${ms:0:6}
>
> Andreas.
>
> --
> Andreas Schwab, SUSE Labs, sch...@suse.de
> GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
> "And now for something completely different."



Re: A small documentation suggestion

2019-01-08 Thread Andreas Schwab
On Jan 07 2019, Keith Thompson  wrote:

> I suggest documenting this behavior. It would be nice to be able to
> depend on the exact format, for example that ${EPOCHREALTIME/*./}
> is always exactly 6 digits long.

ms=${EPOCHREALTIME/*./}00
ms=${ms:0:6}

Andreas.

-- 
Andreas Schwab, SUSE Labs, sch...@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."



A small documentation suggestion

2019-01-07 Thread Keith Thompson
Bash 5.0 adds $EPOCHSECONDS and $EPOCHREALTIME.

The latter expands, each time it's referenced, to the number of
seconds since the epoch with microsecond precision.

Experiment shows that the expansion always has exactly 6 digits after
the decimal point.  For example, if you typed "echo $EPOCHREALTIME"
at just the right moment, it might print "1546925845.00", not
"1546925845.0" or "1546925845".

I suggest documenting this behavior. It would be nice to be able to
depend on the exact format, for example that ${EPOCHREALTIME/*./}
is always exactly 6 digits long.

(The number of digits before the decimal point won't change until 2286;
I'm not too worried about that.)

Proposed patch for doc/bashref.texi (please tweak this if needed):

diff --git doc/bashref.texi doc/bashref.texi
index d33cd571..6381c61a 100644
--- doc/bashref.texi
+++ doc/bashref.texi
@@ -5911,6 +5911,7 @@ Similar to @code{BASH_ENV}; used when the shell
is invoked in
 @item EPOCHREALTIME
 Each time this parameter is referenced, it expands to the number of seconds
 since the Unix Epoch as a floating point value with micro-second granularity
+as if formatted using a @samp{"%.6f"} @code{printf} format
 (see the documentation for the C library function @var{time} for the
 definition of Epoch).
 Assignments to @env{EPOCHREALTIME} are ignored.
@@ -5918,7 +5919,7 @@ If @env{EPOCHREALTIME} is unset, it loses its
special properties, even if
 it is subsequently reset.

 @item EPOCHSECONDS
-Each time this parameter is referenced, it expands to the number of seconds
+Each time this parameter is referenced, it expands to the integer
number of seconds
 since the Unix Epoch (see the documentation for the C library function
 @var{time} for the definition of Epoch).
 Assignments to @env{EPOCHSECONDS} are ignored.

-- Keith Thompson