[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
glitch in an old documentation-example
From: |
Jasper |
Subject: |
glitch in an old documentation-example |
Date: |
Mon, 22 Mar 2010 16:27:58 +0100 |
Hello List,
Searching the net for a way to validate user input to be a well-formed
floating point number I found this example in the bash documentation,
on my system ( Debian-Etch with Bash version 3.1.17 ) it is
located here:
/usr/share/doc/bash/examples/functions/isnum2
it reads:
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
}
# this one handles floating point
isnum3()
{
case "$1" in
'') return 1;; # empty
*[!0-9.+-]*) return 1;; # non-digit, +, -, or .
*?[-+]*) return 1;; # sign as second or later char
*.*.*) return 1;; # multiple decimal points
*) return 0;; # OK
esac
}
But, in the first example, in this line:
'[-+]' | '') return 1;; # empty or bare `-' or `+'
the '[-+]' should be without quotes to work as intended.
Additionally, in the second example the "bare + or -" is not catched.
So in both examples the first line after 'case' should read:
[-+] | '') return 1;; # empty or bare `-' or `+'
Thanks for your time and efforts,
Jasper Noƫ
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- glitch in an old documentation-example,
Jasper <=