bash - 在 BASH 的变量中循环由 `*` 定义的文件
问题描述
我希望能够使用一个脚本指定一个包含 fastq 文件的目录,该脚本将遍历所有文件并执行一些操作。这是我的尝试:
threads=24
current_path=`pwd`
input_file=${current_path}/raw/
files=${current_path}/raw/*
for file in ${files}; do
output_file=${current_path}/${file}_out/
mkdir -m gu=wrx,o=rx ${output_file}
spades.py \
--s1 ${input_file}${file} \
-t ${threads} \
--plasmid \
--careful \
-o ${output_file}
done
所以在这个脚本中我得到一个错误:cannot make directory, directory does not exist
脚本生成一个/home
文件夹。我不知道我是否错误地指定了文件,或者我是否错误地使用了 for 循环。
谢谢!
解决方案
您将文件的完整路径与行中的文件夹连接起来
output_file=${current_path}/${file}_out/
它应该是
output_file=${file}_out/