help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: EPOCHREALTIME to days, hours, minutes, seconds


From: Lawrence Velázquez
Subject: Re: EPOCHREALTIME to days, hours, minutes, seconds
Date: Fri, 20 Aug 2021 16:36:34 -0400
User-agent: Cyrus-JMAP/3.5.0-alpha0-1118-g75eff666e5-fm-20210816.002-g75eff666

On Fri, Aug 20, 2021, at 3:06 PM, Tapani Tarvainen 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.

Under what circumstances does it not work?

    % bash --version | head -n 1
    GNU bash, version 5.1.8(1)-release (x86_64-apple-darwin18.7.0)

    % cat /tmp/foo.bash
    now=$EPOCHREALTIME

    printf -v second1 '%(%S)T.%s' "${now%[^[:digit:]]*}" "${now#*[^[:digit:]]}"
    printf -v minute1 '%(%M)T' "${now%[^[:digit:]]*}"
    printf -v hour1 '%(%H)T' "${now%[^[:digit:]]*}"

    declare -p hour1 minute1 second1

    printf -v second2 '%(%S)T.%s' "${now%[![:digit:]]*}" "${now#*[![:digit:]]}"
    printf -v minute2 '%(%M)T' "${now%[![:digit:]]*}"
    printf -v hour2 '%(%H)T' "${now%[![:digit:]]*}"

    declare -p hour2 minute2 second2

    % bash /tmp/foo.bash
    declare -- hour1="16"
    declare -- minute1="34"
    declare -- second1="41.818451"
    declare -- hour2="16"
    declare -- minute2="34"
    declare -- second2="41.818451"

-- 
vq



reply via email to

[Prev in Thread] Current Thread [Next in Thread]