There isn't a reward for brevity or obfuscation; say what you mean:
isnum2()
{
case "$1" in
[-+] | '') return 1;; # empty or bare `-' or `+'
[-+]*[!0-9]*) return 1;; # non-digit with leading sign
[-+]*) return 0;; # OK
*[!0-9]*) return 1;; # non-digit
*) return 0;; # OK
esac
}
It obviously doesn't handle 0x constants, but could be changed to.
Would you accept this one then, should be general enough, faster too, and
explicit, really mean what is accepted as num literal
It's not a question of me `accepting' anything. It was simply a plea for
clarity. This will give you bash's idea of a number. If you disagree with
that, you'll have to expand on it.
You might want to check for an empty string first, or a missing argument,
depending on your view about whether or not an empty string is equivalent
to 0.
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU chet@case.edu http://tiswww.cwru.edu/~chet/