bash-style for (()) loops

Bug #1749741 reported by Elliott Hughes
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
mksh
Opinion
Wishlist
Unassigned

Bug Description

LTP (https://github.com/linux-test-project/ltp) has a lot of scripts
using the bash for (()) loops, as described in the bash manual:
```
An alternate form of the for command is also supported:

for (( expr1 ; expr2 ; expr3 )) ; do commands ; done

First, the arithmetic expression expr1 is evaluated according to the
rules described below (see Shell Arithmetic). The arithmetic
expression expr2 is then evaluated repeatedly until it evaluates to
zero. Each time expr2 evaluates to a non-zero value, commands are
executed and the arithmetic expression expr3 is evaluated. If any
expression is omitted, it behaves as if it evaluates to 1. The return
value is the exit status of the last command in commands that is
executed, or false if any of the expressions is invalid.
``` (https://www.gnu.org/software/bash/manual/bash.html#Looping-Constructs)

these aren't supported by mksh (or by dash, according to
http://man7.org/linux/man-pages/man1/dash.1.html).

do you feel like this bash extension is in scope for mksh? i might be
able to contribute an implementation (though i have a long-standing
line editing bug i should fix first), but i wanted to check first
whether this would be considered useful enough?

Revision history for this message
Thorsten Glaser (mirabilos) wrote :

No.

They’re ugly enough in C, and they can easily be transformed into something portable:

    for ((a; b; c)); do
        blah
    done

    (( a ))
    while (( b )); do
        blah
        (( c ))
    done

So, *really*, no. I’m translating for loops in C source into while loops as I go, even.

Changed in mksh:
importance: Undecided → Wishlist
status: New → Opinion
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.