bug-bash
[Top][All Lists]
Advanced

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

Re: Exclamation mark when using character classes


From: Kerin Millar
Subject: Re: Exclamation mark when using character classes
Date: Fri, 20 Aug 2021 21:00:18 +0100

On Fri, 20 Aug 2021 19:28:25 +0000
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.

"If an open bracket introduces a bracket expression as in XBD RE Bracket 
Expression, [...] the <exclamation-mark> character ( '!' ) shall replace the 
<circumflex> character ( '^' ) in its role in a non-matching list in the 
regular expression notation."

So says POSIX on the matter of pattern matching notation. In other words, only 
the exclamation-mark is POSIX-specified, although bash happens to tolerate the 
use of a circumflex, in which case it should behave in the exact same way. Are 
you able to show a concrete example of one behaving differently from the other?

-- 
Kerin Millar



reply via email to

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