I'm pretty new to bash scripting, so apologies if this is obvious!
I'm trying to create a bash script to traverse a bunch of files I have of the format ID1.1.fq.stuff, ID1.2.fq.stuff, ID2.1.fq.stuff, ID2.2.fq.stuff .... etc. The script is meant to find files that are paired (both files for ID1, ID2, and so on) and then submit them both together to a program called STAR for downstream processing.
I made the following bash script:
#/!/bin/sh
module load STAR
current_id = ""
current_file = ""
for fqfile in `ls path/*`; do
filename = ${fqfile%%.fq*}
id = ${filename%.*}
if $id == $current_id; then
STAR --readFilesIn $current_file $fqfile --outFileNamePrefix ./$id.bam
else
current_id = $id
current_file = $fqfile
fi
done
When I run it, I get these errors:
[path to $id, without file extensions]: No such file or directory
current_id: command not found
current_file: command not found
What am I doing wrong?
Thank you!
current_id="$id"
for example. Alsols
is nog meant to be used in scripts. So basically there are quite some issues with your code at the moment. – Valentin Bajrami Jul 05 '23 at 19:12if …; then
expects a command in place of…
; the command may be[
with arguments. Your shebang is not a shebang. – Kamil Maciorowski Jul 05 '23 at 19:33#/!/bin/sh
should be#!/bin/sh
and if you want to make use of extra features in Bash, it should probably be#!/bin/bash
or#!/usr/bin/env bash
. – Sotto Voce Jul 05 '23 at 20:42