bash脚本-用于循环
假设我有一个txt文件,如:bash脚本-用于循环,bash,for-loop,find,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} -
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
...
读取时的
循环是一种常见的读取方法。方便的是,如果您将多个变量名传递给read
,它也会同时拆分行
while read -r dir file; do
find "$dir" -name "$file*.bam" -type f
done < file.txt
读取-r dir文件时;做
查找“$dir”-名称“$file*.bam”-类型f
完成
这可能应该使用read-r
(re.shellcheck
)和不同的FD(read-u9
&done9
),以防OP想要在循环中使用stdin吞咽命令。我添加了read-r
。我将传递不同的FD想法;我不想把事情搞得太复杂。谢谢@JohnKugelman我还必须使用fromdos将dos转换为UNIX,因为我的文本文件是在dos中