在 Bash 中循环文件 001 到 909

Looping through file 001 to 909 in Bash

假设我有一个接受两个参数的 python 脚本:

python3 a.py '/001/001.txt' '/after/001'

'/001/001.txt' 将是输入文件路径,'/after/001' 将是输出路径,我想知道如何设置 input_path和 output_path 在下面的 bash 命令中自动循环文件 001 到 909。

i=1; 
while [ $i -le 909 ]; 
do 
    input_path = ''
    output_path = '';
    python3 a.py $input_path $output_path
 
    i=$((i+1)); 
done

我是第一次使用bash命令,所以谁能分享如何解决这个问题?非常感谢

使用 bash 版本 >= 4.0:

for i in {001..909}; do
  echo python3 a.py "/$i/$i.txt" "/after/$i"
done

使用 bash 版本 >= 3.1:

for ((i=1; i<=909; i++)); do
  printf -v x "%03d" "$i"
  echo python3 a.py "/$x/$x.txt" "/after/$x"
done

如果输出看起来没问题,删除 echo