bash shell script two variables in for loop

前端 未结 7 1179
终归单人心
终归单人心 2020-12-09 19:33

I am new to shell scripting. so kindly bear with me if my doubt is too silly.

I have png images in 2 different directories and an executable which takes an images f

7条回答
  •  轮回少年
    2020-12-09 20:17

    This might be another way to use two variables in the same loop. But you need to know the total number of files (or, the number of times you want to run the loop) in the directory to use it as the value of iteration i.

    Get the number of files in the directory:

    ls /path/*.png | wc -l
    

    Now run the loop:

    im1_dir=(~/prev1/*.png) 
    im2_dir=(~/prev3/*.png)
    
    for ((i = 0; i < 4; i++)); do run_black.sh ${im1_dir[i]} ${im2_dir[i]}; done
    

    For more help please see this discussion.

提交回复
热议问题