lundi 5 octobre 2020

copy paste code works but not as a script

I wrote a script with six if statements that looks like this:

#!/usr/bin/bash
if [ -n $var1 ]
        then
            for f in /path/*.fastq.gz
            do
                x=${f/%.fastq.gz/_sample1-forward.fastq.gz}
                y=${f/%.fastq.gz/_sample1-forward.out}
                q=${f/%.fastq.gz/_temp.fastq.gz}
                command [options] -i $f -o $temp${x##*/} 
                cp $temp${x##*/} $temp${q##*/}
            done
        else
            echo "no $var1"
            for f in /path/*.fastq.gz
            do
                q=${f/%.fastq.gz/_temp.fastq.gz}
                cp $f $temp${q##*/}
            done
fi

The other five statements do a similar task for var2 to var6. When I run the script I get unexpected output (no errors no warnings), but when I copy paste each of the if statements to terminal I end up with the exact result I would expect. I've looked for hidden characters or syntax issues for hours now. Could this be a shell issue? Script written on OSX (default zsh) and execution on server (default bash). I have a feeling this issue is similar but I couldn't find an answer to my issue in the replies.

Any and all ideas are most welcome!

Niwatori

Aucun commentaire:

Enregistrer un commentaire