for-loop不工作:尝试将ls转换为数组

时间:2014-12-29 00:10:04

标签: bash shell for-loop

'在运行以下代码时收到语法错误:

#!/bin/bash

for i in (`ls *.nexus`);

do
   awk 'NR >5' /path/to/nexus_files/$i | tr -d "'" | tr " " "\n" | sed 's/uce/>uce/g' > /path/to/fasta_files/${i}.fasta

done

错误:

-bash: syntax error near unexpected token `(

当我删除括号时:

-bash: syntax error near unexpected token 'awk'

1 个答案:

答案 0 :(得分:3)

在您的简单示例中,您可以使用ls命令

for i in *.nexus ; do
    awk ...
done