Re: "printf %d ''" should diagnose the empty string
From:
Zachary Santer
Subject:
Re: "printf %d ''" should diagnose the empty string
Date:
Mon, 10 Feb 2025 12:24:04 -0500
On Mon, Feb 10, 2025 at 11:48 AM Chet Ramey <chet.ramey@case.edu> wrote:
>
> 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.
I question whether that's less obfuscated than mine, but it definitely
doesn't remove leading zeros from the variable for easier use
elsewhere in the script.