Look at the bash
(or sh(1)
) doc, EOF
must be left aligned to the first column of the line. You cannot indent it. If you do, it will not be recognised. This will work:
#!/bin/bash -l
x=`cat x_file_locations`
y=`cat y_list`
for i in $x
do
for j in $y
do
cat << EOF >> ./algo/job_$j.sh
#!/bin/bash -l
#
#$ -N $i
#$ -cwd
#$ -pe smp 10
#$ -l mem_free=20G
algo --input_se $i --output $j --threads=10
# if you indent here, all your jobs will be
# indented.
EOF
#^^ left aligned, don't indent it.
done
done
You cannot even add characters after it in the same line (even a comment is disallowed) If you use FOO
, the shell looks in the text for the regexp ^FOO$
(as a regexp) to match the input. Also, if you quote or delimit the pattern after the <<
operator, then no variable substitution will be made in the redirected text (somewhat arbitrary, but this is a legacy that predates upto version 7 UNIX or more)
This is not according to the way the shell normally parses the input, but it's very safe. Look in the doc of bash(1)
, for these two forms to specify the eof token (depending on if you quote it or not, after the <<
operator).
By the way, as commented to this answer, you had better to use three nested loops, (as you'll see about the utility of the eof token) (look at the places of the redirections, as if you place the input redirect next to the read
command, you will open the file for each read
(and not for the whole while
loop)
#!/bin/sh
file_locations="x_file_locations"
y_list="y_list"
while read loc
do
while read output
do
# you have better not to indent thes
# data of the file, or you'll get an
# unknown reason all indented file.
cat << EOF >> ././././job_${loc}_${output}.sh
#!/bin/bash -l
#
#$ -N ${loc}
#$ -cwd
#$ -pe smp 10
#$ -l mem_free=20G
algo --input_se "${loc}" --output "${output}" --threads=10
EOF
done < "${y_list}"
done < "${file_locations}"
but if you want the x_file_locations
and the y_list
contents also be included in the shell script:
#!/bin/sh
DATE=$(date +%Y%m%d-%H%M)
while read loc
do
while read output
do
# you have better not to indent thes
# data of the file, or you'll get an
# unknown reason all indented file.
cat << EOF >> "././././job_${loc}_${output}.sh"
#!/bin/bash -l
#
#$ -N '${loc}'
#$ -cwd
#$ -pe smp 10
#$ -l mem_free=20G
scripts/${output}.sh --input_se "${loc}" --output "${output}.log" --threads=10
EOF
done << EOF
Population
Overall-Temp
Rain
Vacation-Places
EOF
done << EOF
Paris
Amsterdam
Oviedo
Geneve
Zurich
Helsinki
Warsaw
Oulu
EOF