bug-bash
[Top][All Lists]
Advanced

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

Exclamation mark when using character classes


From: hancooper
Subject: Exclamation mark when using character classes
Date: Sat, 21 Aug 2021 14:55:38 +0000

‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
On Saturday, August 21, 2021 11:25 AM, Ilkka Virta <itvirta@gmail.com> wrote:

> What do you get with [![:digit:]] then? It seems to work the same with both
> ! and ^ here:
>
> $ now=$EPOCHREALTIME
> $ echo "${now%[^[:digit:]]}" "${now#[^[:digit:]]}"
> 1629544775 183030
> $ echo "${now%[![:digit:]]}" "${now#[![:digit:]]}"
> 1629544775 183030
>
> On Fri, Aug 20, 2021 at 10:30 PM hancooper via Bug reports for the GNU
> Bourne Again SHell bug-bash@gnu.org wrote:
>
> > I am using EPOCHREALTIME and then computing the corresponding human
> > readable form, that can handle
> > changes in locale
> > 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.

I got it backwards.  POSIX specifies ! for use in globs, and bash
permits ^ as an extension, for people who are used to ^ from regular
expressions.

Had "tested" this using grep or [[ =~ ]] or something else that uses
regular expressions, not globs.







reply via email to

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