For loop with an argument based range

前端 未结 3 1828
感情败类
感情败类 2021-01-23 09:33

I want to run certain actions on a group of lexicographically named files (01-09 before 10). I have to use a rather old version of FreeBSD (7.3), so I can\'t use yummies like

3条回答
  •  渐次进展
    2021-01-23 10:06

    Ok, I finally got it!

    #!/bin/bash
    #BSD-only iteration method    
    #for day in `jot $1 $2`
    for ((day=$1; day<$2; day++))
    do
        echo $(printf %02d $day)
    done
    

    I initially wanted to use the cycle iterator as a "day" in file names, but now I see that in my exact case it's easier to iterate through normal numbers (1,2,3 etc.) and process them into lexicographical ones inside the loop. While using jot, remember that $1 is the numbers amount, and the $2 is the starting point.

提交回复
热议问题