|
| From: | Chet Ramey |
| Subject: | Re: "printf %d ''" should diagnose the empty string |
| Date: | Mon, 10 Feb 2025 11:48:02 -0500 |
| User-agent: | Mozilla Thunderbird |
On 2/10/25 11:34 AM, Zachary Santer wrote:
On Mon, Feb 10, 2025 at 9:20 AM Phi Debian <phi.debian@gmail.com> wrote:If 'best *general*' refer to the shortest line noise does $((${i/?([-+])/&10#})) Qualify for better than best ? :-)And then this isn't even half as good:
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.
--
``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/
OpenPGP_signature.asc
Description: OpenPGP digital signature
| [Prev in Thread] | Current Thread | [Next in Thread] |