[Top][All Lists]

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

why are \d and \D not implemented but don't throw errors in regex?

From: Craig Steffen
Subject: why are \d and \D not implemented but don't throw errors in regex?
Date: Sat, 7 Dec 2013 11:06:22 -0600


I'm working on some bash scripts for work where I'm using a regular
expression to grab a number from the output of another command.

I've gotten fairly adept at using regular expressions, in perl mostly,
but I just couldn't get it to work in bash.

One reason was that the regex search is supposed to be a variable
rather than an literal inside the [[ ]] expression.

However, the second reason was that \d and \D are apparently not
implemented, even though \s and \S are?  And furthermore, the match
just silently fails without indicating anything is amiss.  After
searching, [[:digit:]] does work instead of \d.

Is there any particular reason why \s is implemented as a regex
specification in bash but \d isn't?  And if there's a good reason for
not implementing it, can there be a syntax error or at least a warning
if the script is trying to do something that works in other regular
expressions but produces the exactly the wrong behavior in that
context in bash?

In case it matters, bash on my work machine is:
address@hidden 10:06 ~/prompt_fu PD_-___-PGI-_ $ bash --version
GNU bash, version 3.2.51(1)-release (x86_64-suse-linux-gnu)
Copyright (C) 2007 Free Software Foundation, Inc.
address@hidden 10:30 ~/prompt_fu PD_-___-PGI-_ $

That's a Cray XE6 system with Interlagos CPUs.  The OS is SLES-based.

My laptop, where I created a test script to root out the problem, is:
address@hidden:~/work/shells$ bash --version
GNU bash, version 4.2.45(1)-release (i686-pc-linux-gnu)
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

It's a Sony Vaio running Ubuntu 13.04

Both versions of bash behaved the same with regards to \d vs. [[:digit:]]

Thanks.  Sincerely,

Craig Steffen

reply via email to

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