bash 脚本 - for 循环

时间:2021-03-18 01:34:59

标签: bash for-loop find

假设我有一个 txt 文件,例如:

CGND_01234    CGND-HRA-00736
CGND_34563    CGND-HRA-00567
...

如何在 bash 中为下面的行创建一个 for 循环来迭代文件中的每一行?

find ./${first_word_in_the_first_line} -name "${second_word_in_the_first_line}*.bam" -type f 
find ./${first_word_in_the_second_line} -name "${second_word_in_the_second_line}*.bam" -type f
...

1 个答案:

答案 0 :(得分:6)

while read 循环是 read a file line-by-line 的常用方法。方便的是,如果您将多个变量名称传递给 read,它也会同时拆分该行。

while read -r dir file; do
    find "$dir" -name "$file*.bam" -type f 
done < file.txt