在BASH中的变量中循环遍历由*定义的文件

时间:2019-11-20 11:43:24

标签: bash loops

我希望能够使用一个脚本来指定包含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循环。

谢谢!

1 个答案:

答案 0 :(得分:0)

您将文件的完整路径连接到一行中的文件夹

output_file=${current_path}/${file}_out/

应该是

output_file=${file}_out/