Looping over pairs of values in bash
问题 I have 10 text files and I want to paste each file with its pair, such that I have 5 total files. I tried the following: for i in 4_1 5_1 6_1 7_1 8_1 do for j in 4_2 5_2 6_2 7_2 8_2 do paste ${i}.txt ${j}.txt > ${i}.${j}.txt done done However, this code combines every possible combination instead of just combining the matching pairs. So I would like file 4_1.txt to be paired with 4_2.txt , 5_1.txt with 5_2.txt , etc. 回答1: If you want to use one variable and perform and action with it, you