如何使bash脚本与另一个命令一起工作? [英] How to make the bash script work with one command after another?

查看:88
本文介绍了如何使bash脚本与另一个命令一起工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个如下的bash脚本.首先,它将sorted.bam文件作为输入,并使用字符串"工具将每个示例gtf作为输出.然后,将每个样本gtf的路径提供给mergelist.txt.然后对它们使用"stringtie merge"来获取"stringtie_merged.gtf".

I have a bash script like below. First it will take sorted.bam files as input and use "stringtie" tool give each sample gtf as output. Then path for each sample gtf will be given into mergelist.txt. and then use "stringtie merge" on them to get "stringtie_merged.gtf".

我总共有40个sort.bam文件.

I totally have 40 sorted.bam files.

for sample in /path/*.sorted.bam
do
dir="/pathto/hisat2_output"
dir2="/pathto/folder"
base=`basename $sample '.sorted.bam'`
"stringtie -p 8 -G gencode.v27.primary_assembly.annotation_nochr.gtf -o ${dir2}/stringtie_output/${base}/${base}_GRCh38.gtf -l ${dir2}/stringtie_output/${base}/${base} ${dir}/${base}.sorted.bam; ls ${dir2}/stringtie_output/*/*_GRCh38.gtf > mergelist.txt; stringtie --merge -p 8 -G gencode.v27.primary_assembly.annotation_nochr.gtf -o ${dir2}/stringtie_output/stringtie_merged.gtf mergelist.txt"
done

在所有sorted.bam文件上运行脚本并完成作业后,我用;分隔了命令,我看到mergelist.txt仅具有33个示例gtf的路径.这意味着合并list.txt中缺少其他7个示例gtf的路径.

I separated the commands with ; After running the script on all sorted.bam files and after completing the job I see that mergelist.txt has paths only for 33 sample gtf's. Which means the path for other 7 sample gtfs is missing in merge list.txt.

是用;分隔命令吗,还是还有其他方法?

Is Separating the commands with ; right one or is there any other way?

该脚本应首先使用一个命令,然后在输出中在文本文件中指定路径,然后再使用另一个命令.

The script should use one command first and with the output the paths need to be given in the text file and then use the other command.

推荐答案

您尚未使用分号分隔命令;您已经调用了一个嵌入了分号的命令.考虑简单的脚本:

You haven't separated the commands with semi-colons; you've invoked a single command that has semi-colons embedded in it. Consider the simple script:

"ls; pwd"

此脚本不会调用ls,然后再调用pwd.相反,外壳程序将在PATH中搜索以查找名为ls; pwd的文件(即名称中带有分号和空格的文件),可能找不到该文件并返回错误消息.您需要删除双引号.

This script does not call ls followed by pwd. Instead, the shell will search the PATH looking for a file named ls; pwd (that is, a file with a semi-colon and a space in its name), probably not find one and respond with an error message. You need to remove the double quotes.

这篇关于如何使bash脚本与另一个命令一起工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆