bash shell script two variables in for loop

前端 未结 7 1174
终归单人心
终归单人心 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:19

    If you don't mind going off the beaten path (bash), the Tool Command Language (TCL) has such a loop construct:

    #!/usr/bin/env tclsh
    
    set list1 [glob dir1/*]
    set list2 [glob dir2/*]
    
    foreach item1 $list1 item2 $list2 {
        exec command_name $item1 $item2
    }
    

    Basically, the loop reads: for each item1 taken from list1, and item2 taken from list2. You can then replace command_name with your own command.

提交回复
热议问题