[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Suggested BASH Improvement
From: |
alex xmb sw ratchev |
Subject: |
Re: Suggested BASH Improvement |
Date: |
Wed, 18 Sep 2024 04:46:01 +0200 |
another is ${var##0}
On Wednesday, September 18, 2024, BRUCE FOWLER via Bug reports for the GNU
Bourne Again SHell <bug-bash@gnu.org> wrote:
> An interesting problem I ran into recently:
>
> I have a shell script that I run about once a month that
> "screen-scrapes" from the output of another program using the
> substring capability, e.g. ${data_line:12:2}. This is pulling
> out the two-digit month ranging from "01" to "12".
>
> This worked fine, even giving the right answers, for
> months earlier in the year. Then came August, and it went
> sideways because the leading "0" was forcing the number to be
> interpreted as octal. My first reaction was, What's going on,
> this has run just fine for months. The second reaction was,
> WTF, who uses octal anymore? But I understand it is because
> of C-language compatibility. I could use the [base#]n form
> but that gets awkward.
>
> My proposal is to add a new "shopt" option, say called "XOCTAL",
> that would suppress the octal interpretation of numbers with
> leading zeros. The default would be "off", so scripts would
> run just as now. Just the existence of this option might
> alert non-expert shell coders to the subtle and surprising
> "bug" that I encountered.
>
> Even the venerable BASH shell still has room for modernization
> and improvement. Thank you for your interest and consideration.
>
> |======================
> |Bruce Fowler 410-320-8200
> |[ 39°1.55'N - 76°28.16'W ]
> |======================
>
>