dash.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Pattern matching faster than math
@ 2015-03-25 13:51 Alex Waite
  0 siblings, 0 replies; only message in thread
From: Alex Waite @ 2015-03-25 13:51 UTC (permalink / raw)
  To: dash


This isn't a problem per-se, but I'm curious if anyone can shed some 
light on why this is so.

I have a script where I'm checking if the contents of a variable is an 
integer. An easy/hacky way to do this is

[ "$var" -ge 0 2> /dev/null ] || echo "is not int"

But this caused posh to segfault, so I went for a pattern matching 
solution instead:

[ -z "${var##*[!0-9]*}" ] && echo "is not int"

This works well, and it makes posh happy. But what's surprising to me is 
that it's faster.

I have more of a write-up in a commit message: 

Any thoughts or insight? Am I making some faulty assumption here?

Thanks for your time.


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2015-03-25 13:52 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-25 13:51 Pattern matching faster than math Alex Waite

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).