0

I have the following bash script:

#!/bin/bash
$db=DB
$H=6973
$cov=38
for i in $(find . -type f -name "*.*.las");
do
  cat <<EOF
  #qsub <<EOF
#!/bin/bash -l

#PBS -N DASqv
#PBS -l walltime=48:00:00
#PBS -j oe
#PBS -l mem=30G
#PBS -l ncpus=1
#PBS -M m.lorenc@qut.edu.au
##PBS -m bea

cd \$PBS_O_WORKDIR

source activate thegenemyers

DAStrim=$(DASqv -v -H$H -c$cov $db $i | grep Recommend - | sed "s|Recommend ||g" - | sed "s|'||g" -)

DAStrim $db $i 

EOF

done

Unfortunately, I got this error:

sh Dascrubber_pbs.sh

DASqv: -H '' argument is not an integer
  #qsub <<EOF
#!/bin/bash -l

#PBS -N DASqv
#PBS -l walltime=48:00:00
#PBS -j oe
#PBS -l mem=30G
#PBS -l ncpus=1
#PBS -M m.lorenc@qut.edu.au
##PBS -m bea

cd $PBS_O_WORKDIR

source activate thegenemyers

DAStrim=

DAStrim  ./DB.309.las

I would have expected to see e.g. DAStrim=$(DASqv -v -H6973 -c38 DB ./DB.82.las | grep Recommend - | sed "s|Recommend ||g" - | sed "s|'||g" -).

What did I miss?

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255

1 Answers1

2

There are two issues:

  1. As steeldriver pointed out, assignments in shells (other than C shell derivatives) look like
    variable=value
    not
    $variable=value
  2. If a here-document’s delimiter string is not quoted, the contents of the here-document are interpreted (expanded).  So you shouldn’t be expecting to see DAStrim=$(DASqv -v -H6973 ...), you should be expecting to see DAStrim=whatever_the_output_of_DASqv_is.  If, for some reason, you wanted to see the command, you should quote the EOF, or any of its characters (so you could use 'EOF', "EOF", \EOF, or assorted other variations), or escape the $.  For example,
    $ WORKDIR=/tmp
     
    $ i=foobar.las
     
    $ cat << EOF
    cd \$WORKDIR
    ls -l "$i"
    today=$(date)
    EOF
    cd $WORKDIR                             (output)
    ls -l "foobar.las"
    today=Tue, Jan 30, 2018  1:27:42 AM
     
    $ cat << 'EOF'
    cd \$WORKDIR                            (same input as above)
    ls -l "$i"
    today=$(date)
    EOF
    cd \$WORKDIR                            (output)
    ls -l "$i"
    today=$(date)
     
    $