I am using EOF to generate bash scripts that run the Rscripts. In the Rscript I used basename
to specify the output file name.
When I use EOF
to generate a list of bash scripts, I could not get basename
to work. The error message is shown below. I was still able to get the bash scripts generated but the ${AF}
turned into a blank in both places where it presented. Very strange!
I had the bash script tested and it is working so I know the problem is somewhere between EOF
and basename
.
How can I use basename
with EOF
? Or is there any alternative methods? Thank you.
for letter in {A..Z}
do cat <<- EOF > batch_${letter}.sh
#!/bin/bash
module load R/3.5.1
R_func="/home/dir/R_func"
TREAT="/home/dir/POP"
BASE="/home/dir/base"
OUTPUT="/home/dir/tmp"
for AF in ${BASE}/${letter}*.txt_step3; do
Rscript ${R_func}P_tools.R \
--ptool ${R_func}/P_tools_linux \
--group ${AF} \
--treat ${TREAT}/pop_exclude24dup \
--out ${OUTPUT}/OUT_$(basename ${AF%%_txt_step3})_noregress \
--binary-target F; done
EOF
done
This is the error message
basename: missing operand Try 'basename --help' for more information.
$
fromR_func
should be quoted, too. Fixed now. – Mar 26 '19 at 21:51