- Feature Articles
- CodeSOD
- Error'd
-
Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
So the frist job isn't 0.
But if memory serves, old versions of bash couldn't calculate expressions. You had to call out to another program: bc, dc, ...
Admin
Bash has supported "arithmetic evaluation" since at least version 2.0, released on 31 December 1996 (so, really 1997).
However, what you're probably referring to is the fact that this arithmetic is always integer-based : if you need anything involving the decimal dot, you have to shell out to dc/bc indeed. This may also serve as an indicator that what you're doing is too big for Bash and you should be using a more powerful language instead.
Admin
Though if they used
bc, this wouldn't be a WTF either. The choice of AWK is… weird.Admin
Dare I say it? Yes, I dare. One might even say that the choice of AWK is awkward.
Admin
Indeed!
Arrays in Awk, just like field numbers, are 1-indexed, so the "developer" <koff> probably asserted that Job Number Zero is impossible.
Admin
I'm an AWK fan. I use it a lot. I mean, A LOT! And I agree - "The choice of AWK is... weird."
Admin
Before bash had built-in arithmetic, the normal way to do simple arithmetic in shell scripts was with
expr. That's been around practically forever (it was in V7).Admin
By my standards, this doesn't rate: I don't look at it and say WTF. Sure, the awkwardness is distasteful, but [a] it works and [b] it's clear what it is doing. I can't say that about most of the code I've inherited over the years.
Addendum 2025-10-20 09:47: meant to add [c] it's not doing anything unsupported.
Admin
I'm curious as to why such a number is needed since it just wraps around.
Admin
bat = Bash/Awk tangle
Admin
Hey, Carl From The Article, let's put on hats and go eat people.
Admin
Hey, CarlFromTheArticle, let's put on hats and go eat people.
Admin
Was there in System V release 4 (can't remember earlier)
Admin
Best part is, even Batch script has access to integer arithmetic and logical functions through SET /A. (Not sure since when but at least Vista or XP)
For details: https://ss64.com/nt/set.html
Admin
Hence, Perl.
Admin
Perl? Now THERE is a WTF!
Admin
But that wouldn't fit the specification for
because using
modwould result in job 0 coming after job 999, not 1.Admin
Indeed the choice of AWK is odd. I'd used Python.
num=$( python -c "print(($num + 1) % 1000)" )