bash 脚本 - for 循环

0 bash for-loop find

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

CGND_01234    CGND-HRA-00736
CGND_34563    CGND-HRA-00567
...
Run Code Online (Sandbox Code Playgroud)

如何在 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
...
Run Code Online (Sandbox Code Playgroud)

Joh*_*ica 6

while read环是一种常见的方式读取文件中的行由行。方便的是,如果您将多个变量名称传递给read它,它也会同时拆分该行。

while read -r dir file; do
    find "$dir" -name "$file*.bam" -type f 
done < file.txt
Run Code Online (Sandbox Code Playgroud)