Skip to content

Commit f0aee80

Browse files
committed
Make sure for-loop variable is reset
1 parent 0ed4277 commit f0aee80

2 files changed

Lines changed: 3 additions & 1 deletion

File tree

converters/bash/converter.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,13 @@ func (c *converter) ElseEnd() error {
179179
}
180180

181181
func (c *converter) ForStart() error {
182+
c.addLine(fmt.Sprintf(`%s=`, c.mustCurrentForVar()))
182183
c.addLine("while true; do")
183184
return nil
184185
}
185186

186187
func (c *converter) ForIncrementStart() error {
187-
c.addLine(fmt.Sprintf(`if [ ! -z ${%s+x} ]; then`, c.mustCurrentForVar())) // https://stackoverflow.com/a/13864829
188+
c.addLine(fmt.Sprintf(`if [ ! -z ${%s} ]; then`, c.mustCurrentForVar())) // https://stackoverflow.com/a/13864829
188189
return nil
189190
}
190191

converters/batch/converter.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@ func (c *converter) ForStart() error {
350350
c.fors = append(c.fors, forInfo{
351351
label: label,
352352
})
353+
c.addLine(fmt.Sprintf(`set "%s="`, c.mustCurrentForVar()))
353354
c.addLine(label)
354355
return nil
355356
}

0 commit comments

Comments
 (0)