错误如下:
merge_star.sh: line 19: syntax error near unexpected token `('
merge_star.sh: line 19: `cat <(cat ~/asn_project/alignment_sorted/tmp/header.txt | sed 's/ /\t/g') ~/asn_project/alignment_sorted/tmp/tmp.out > ~/asn_project/alignment_sorted/STAR_counts.txt'
有问题的 .sh 脚本中的行:
cat <(cat ~/asn_project/alignment_sorted/tmp/header.txt | sed 's/ /\t/g') ~/asn_project/alignment_sorted/tmp/tmp.out > ~/asn_project/alignment_sorted/STAR_counts.txt
#!/bin/bash
# create header file
echo gene_name $(cd ~/asn_project/alignment_sorted && ls *_ReadsPerGene.out.tab | sed s/_ReadsPerGene.out.tab// | sort -u) > ~/asn_project/alignment_sorted/tmp/header.txt
# Place each sample's STAR gene count file - ReadsPerGene.out.tab in the tmp/ directory
# The 2nd column (-f2) of ReadsPerGene.out.tab contains the non-stranded counts
for sample in $(cd ~/asn_project/alignment_sorted && ls *_ReadsPerGene.out.tab | sed s/_ReadsPerGene.out.tab// | sort -u)
do
echo ${sample}
cat ~/asn_project/alignment_sorted/${sample}_ReadsPerGene.out.tab | tail -n +5 | cut -f2 > ~/asn_project/alignment_sorted/tmp/${sample}.count
done
# get a list of gene ids (-f1)
tail -n +5 ~/asn_project/alignment_sorted/N_1_ReadsPerGene.out.tab | cut -f1 > ~/asn_project/alignment_sorted/tmp/geneids.txt
# combine all the columns of the count files
paste ~/asn_project/alignment_sorted/tmp/geneids.txt ~/asn_project/alignment_sorted/tmp/*.count > ~/asn_project/alignment_sorted/tmp/tmp.out
# add the header
cat <(cat ~/asn_project/alignment_sorted/tmp/header.txt | sed 's/ /\t/g') ~/asn_project/alignment_sorted/tmp/tmp.out > ~/asn_project/alignment_sorted/STAR_counts.txt
# remove the tmp folder
rm -rf ~/asn_project/alignment_sorted/tmp
我对 .sh 脚本编码很陌生,我不知道错误告诉我要修复什么。任何帮助表示赞赏。
答案1
在评论中你说您正在使用 运行此脚本sh merge_star.sh
。这意味着您正在用来sh
运行脚本,但第一行 ( #!/bin/bash
) 意味着它是为bash
.在某些系统上sh
和bash
是相同的,但在其他系统上则不同;并且,当作为 调用时sh
,Bash 会关闭一些非 POSIX 功能,包括(对于 5.0 以下的版本)进程替换 ( <(...)
)。因此,使用正确的 shell 和正确的调用非常重要。
使用bash merge_star.sh
或更好的是,使脚本可执行(chmod a+x merge_star.sh
),然后直接运行(./merge_star.sh
)