[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: EPOCHREALTIME to days, hours, minutes, seconds
From: |
Emanuele Torre |
Subject: |
Re: EPOCHREALTIME to days, hours, minutes, seconds |
Date: |
Fri, 20 Aug 2021 23:47:43 +0200 |
also, both [![:digit:]]* and [^[:digit:]]* work for me:
bash$ declare -p BASH_VERSINFO
declare -ar BASH_VERSINFO=([0]="5" [1]="1" [2]="8" [3]="1"
[4]="release" [5]="x86_64-pc-linux-gnu")
bash$ printf '%s\n' "${EPOCHREALTIME%[![:digit:]]*}"
1629496011
bash$ printf '%s\n' "${EPOCHREALTIME%[^[:digit:]]*}"
1629496014
On 20/08/2021, Emanuele Torre <torreemanuele6@gmail.com> wrote:
>> 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
>>
>>
>
- Re: EPOCHREALTIME to days, hours, minutes, seconds, (continued)
- Re: EPOCHREALTIME to days, hours, minutes, seconds, Tapani Tarvainen, 2021/08/20
- Re: EPOCHREALTIME to days, hours, minutes, seconds, Andreas Kusalananda Kähäri, 2021/08/20
- Re: EPOCHREALTIME to days, hours, minutes, seconds, Emanuele Torre, 2021/08/20
- Re: EPOCHREALTIME to days, hours, minutes, seconds, Alex fxmbsw7 Ratchev, 2021/08/20
- Re: EPOCHREALTIME to days, hours, minutes, seconds, Tapani Tarvainen, 2021/08/20
- Re: EPOCHREALTIME to days, hours, minutes, seconds, Tapani Tarvainen, 2021/08/20
- Re: EPOCHREALTIME to days, hours, minutes, seconds, Lawrence Velázquez, 2021/08/20
- Re: EPOCHREALTIME to days, hours, minutes, seconds, Greg Wooledge, 2021/08/20
- Re: EPOCHREALTIME to days, hours, minutes, seconds, Tapani Tarvainen, 2021/08/21
- Re: EPOCHREALTIME to days, hours, minutes, seconds, Emanuele Torre, 2021/08/20
- Re: EPOCHREALTIME to days, hours, minutes, seconds,
Emanuele Torre <=
- Re: EPOCHREALTIME to days, hours, minutes, seconds, Lawrence Velázquez, 2021/08/20
- Re: EPOCHREALTIME to days, hours, minutes, seconds, Emanuele Torre, 2021/08/20
- Prev by Date:
Re: EPOCHREALTIME to days, hours, minutes, seconds
- Next by Date:
Re: EPOCHREALTIME to days, hours, minutes, seconds
- Previous by thread:
Re: EPOCHREALTIME to days, hours, minutes, seconds
- Next by thread:
Re: EPOCHREALTIME to days, hours, minutes, seconds
- Index(es):