Re: EPOCHREALTIME to days, hours, minutes, seconds
From:
Emanuele Torre
Subject:
Re: EPOCHREALTIME to days, hours, minutes, seconds
Date:
Fri, 20 Aug 2021 23:41:02 +0200
> Incidentally, [![:digit:]] does not work there, you need to use the
> POSIX-specified caret (^) instead of an exclamation mark when using
> character classes. I'm not sure if this is intentional or a bug in
> bash; man page doesn't seem to mention it.
I don't think POSIX actually defines character class negation for glob patterns
see:
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_13_03
On 20/08/2021, Tapani Tarvainen <bash@tapanitarvainen.fi> wrote:
> On Fri, Aug 20, 2021 at 06:39:04PM +0200, Emanuele Torre
> (torreemanuele6@gmail.com) wrote:
>
>> Also, EPOCHREALTIME may not have "." as the decimal delimiter since it
>> uses the one of the current locale (LC_NUMERIC). So it's more
>> appropriate to use [!0-9] rather than ".".
>>
>> now=$EPOCHREALTIME
>> printf -v second '%(%S)T.%s' "${now%[!0-9]*}" "${now#*[!0-9]}"
>> printf -v minute '%(%M)T' "${now%[!0-9]*}"
>> printf -v hour '%(%H)T' "${now%[!0-9]*}"
>
> Good point. Though of course that may break in locales that
> have additional digit characters (say, Arabic or Lao).
> So instead of [!0-9] it'd be better to use [^[:digit]] in there:
>
> now=$EPOCHREALTIME
> printf -v second '%(%S)T.%s' "${now%[^[:digit:]]*}"
> "${now#*[^[:digit:]]}"
> printf -v minute '%(%M)T' "${now%[^[:digit:]]*}"
> printf -v hour '%(%H)T' "${now%[^[:digit:]]*}"
>
> Incidentally, [![:digit:]] does not work there, you need to use the
> POSIX-specified caret (^) instead of an exclamation mark when using
> character classes. I'm not sure if this is intentional or a bug in
> bash; man page doesn't seem to mention it.
>
> --
> Tapani Tarvainen
>
>