Bash script outputs the command but will not run it

Viewed 46

I have written a script that is shown below. However, when I run the script it just outputs the final command instead of running it. What do I need to add at the end so that the command will be run?

Thank you

#!/bin/bash -l
#$ -cwd
# file name: singlecell.sh


rundir=$1
outdir=$2
samplesheet=$3

USAGE="Usage: $0 -i [path to input run directory]  -o [path to output directory] -s [path to sample sheet]"

while getopts i:o:s:h opt
  do
  case "$opt" in
      i) RunDir="$OPTARG";;
      o) OutDir="$OPTARG";;
      s) SampSheet="$OPTARG";;
      h) echo $USAGE; exit 1
  esac
done

if [[ $RunDir == "" || $OutDir == ""  || $SampSheet == "" ]]
    then
    echo $USAGE
    exit 1
fi

# asssume only one index type per run 
index8=`grep "SI-GA\|SI-NA" $SampSheet | wc -l`
ignore=""
# check if single indexes.
if [ $index8 -gt 0 ]; then
   ignore="--filter-single-index"
else
  ignore="--filter-dual-index"
fi
   

cmd="cellranger mkfastq --run=$RunDir --output-dir=$OutDir --csv=$SampSheet --localcores=8 --localmem=40 $ignore --barcode-mismatches=0"

echo $cmd
$cmd
1 Answers

You can replace the last lines:

cmd="cellranger mkfastq --run=$RunDir --output-dir=$OutDir --csv=$SampSheet --localcores=8 --localmem=40 $ignore --barcode-mismatches=0"

echo $cmd
$cmd

With:

cellranger mkfastq --run=$RunDir --output-dir=$OutDir --csv=$SampSheet --localcores=8 --localmem=40 $ignore --barcode-mismatches=0

If you are in doubt the program actually ran as it may not give output in the terminal, the usual way is to check for its return value. This is the general status value returned by a program, such as the common return 0; at the end of main function in C programs.

cellranger mkfastq --run=$RunDir --output-dir=$OutDir --csv=$SampSheet --localcores=8 --localmem=40 $ignore --barcode-mismatches=0
cellranger_ret=$?
echo "cellranger_ret = ${cellranger_ret}"

This gives you a clue if the expected output from the program didn't show up and it is not reporting any error. Typically 0 means success and other values indicate error. Other useful tip is to look for debug related parameters (command line arguments) that will allow you to increase the verbosity level of the program.

Related