• Hanzito (unregistered)

    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, ...

  • Debra (unregistered)

    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.

  • (author) in reply to Hanzito

    Though if they used bc, this wouldn't be a WTF either. The choice of AWK is… weird.

  • (nodebb) in reply to Remy Porter

    The choice of AWK is… weird

    Dare I say it? Yes, I dare. One might even say that the choice of AWK is awkward.

  • (nodebb) in reply to Hanzito

    And if you know how to use Awk, why would you use anything but Awk?

    Indeed!

    So the frist job isn't 0.

    Arrays in Awk, just like field numbers, are 1-indexed, so the "developer" <koff> probably asserted that Job Number Zero is impossible.

  • (nodebb) in reply to Remy Porter

    Though if they used bc, this wouldn't be a WTF either. The choice of AWK is… weird.

    I'm an AWK fan. I use it a lot. I mean, A LOT! And I agree - "The choice of AWK is... weird."

  • (nodebb)

    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).

  • (nodebb)

    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.

  • John (unregistered)

    I'm curious as to why such a number is needed since it just wraps around.

  • Duke of New York (unregistered)

    bat = Bash/Awk tangle

  • carl witthoft (unregistered)

    Hey, Carl From The Article, let's put on hats and go eat people.

  • (nodebb)

    Hey, CarlFromTheArticle, let's put on hats and go eat people.

  • linepro (unregistered) in reply to Barry Margolin

    Was there in System V release 4 (can't remember earlier)

  • Klimax (unregistered)

    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

  • (nodebb) in reply to Debra

    Hence, Perl.

  • (nodebb) in reply to RandalSchwartz

    Perl? Now THERE is a WTF!

  • (nodebb)
    I don't mind the desire to limit job count by way of mod(1000) 
    

    But that wouldn't fit the specification for

    that is to say, job 1 comes after job 999
    

    because using mod would result in job 0 coming after job 999, not 1.

  • (nodebb)

    Indeed the choice of AWK is odd. I'd used Python.

    num=$( python -c "print(($num + 1) % 1000)" )

Leave a comment on “The Batch Managing Batch File”

Log In or post as a guest

Replying to comment #685712:

« Return to Article