我是bash脚本的新手,但我想在bash脚本中将一些文件设置为for循环中的变量。我有这样的代码:
a=home/my_directory/*.fasta
b=home/my_directory/*.aln
for i in {1..14} # I have 14 files in my_directory with file extension .fasta
do
clustalo -i $a -o $b # clustalo is a command of Clustal Omega software, -i is
# input file, -o is output file
done我只想在my_directory中使用我所有的fasta文件,并创建另外14个新的aln文件。但是有了这段代码,它就不能工作了,因为集群程序不能识别这个集合文件。所以如果你能帮忙我会很感激的。
发布于 2013-08-07 17:47:29
如果您知道确切有14个文件,请执行以下操作:
for i in {1..14}; do
clustalo -i home/my_directory/$a.fasta -o home/my_directory/$b.aln
done如果您想处理所有的*.fasta文件,不管有多少文件,请执行以下操作:
for file in home/my_directory/*.fasta; do
clustalo -i "$file" -o "${file%.fasta}.aln"
done为了理解这一点,${file%.fasta}给我们去掉了$file的.fasta扩展。
如果要首先将文件名存储在变量中,最好的做法是使用数组变量。为此,您可以在变量赋值周围添加括号,然后使用奇怪的语法"${array[@]}"访问数组值。
files=(home/my_directory/*.fasta)
for file in "${files[@]}"; do
clustalo -i "$file" -o "${file%.fasta}.aln"
donehttps://stackoverflow.com/questions/18110188
复制相似问题