How to make the bash script work with one command after another? How to make the bash script work with one command after another? shell shell

How to make the bash script work with one command after another?


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"

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.


What's wrong with multiple lines, as you already have more than one line:

dir="/pathto/hisat2_output"dir2="/pathto/folder"for sample in /path/*.sorted.bam ;do  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.txtdone

Anyway, I don't see the point in having the second stringtie command inside the loop, it should work fine just after.

If stringtie is able process STDIN you might get away without the mergelist.txt by using:

stringtie --merge -p 8 -G gencode.v27.primary_assembly.annotation_nochr.gtf -o ${dir2}/stringtie_output/stringtie_merged.gtf <<< $(echo ${dir2}/stringtie_output/*/*_GRCh38.gtf)


you should double quote your variables and use $( command ) instead backticks

base=$( basename $sample '.sorted.bam' ) : you have a space in filenames??

prefer:

base=$( basename "$sample.sorted.bam" ) # with or without space

if you have spaces, you must double quote:

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...