Bash script not working in Ubuntu in Windows 10

Solution 1:

Use heredoc instead:

for FILE in *fastq; #change file type when needed (e.g., fasta, fastq, fastq.gz)
do

cat <<-EOF > ${FILE}.sh
#!/bin/bash

#SBATCH --partition=nonpre             # Partition (job queue)
#SBATCH --requeue                      # Return job to the queue if preempted
#SBATCH --job-name=samples             # Assign a short name to your job
#SBATCH --nodes=1                      # Number of nodes you require
#SBATCH --ntasks=1                     # Total # of tasks across all nodes
#SBATCH --cpus-per-task=64             # Cores per task (>1 if multithread tasks)
#SBATCH --mem=180000                   # Real memory (RAM) required (MB)
#SBATCH --time=72:00:00                # Total run time limit (HH:MM:SS)
#SBATCH --output=slurm.%N.${FILE}.out  # STDOUT output file
#SBATCH --error=slurm.%N.${FILE}.err   # STDERR output file (optional)

#ADD WHATEVER CODE YOU WANT HERE AS YOUR SLURM JOB SUBMISSION

nsacct --format=JobID,JobName,NTasks,NNodes,NCPUS,MaxRSS,AveRSS,AveCPU,Elapsed,ExitCode -j \$SLURM_JOBID #this will get job run stats from SLURM; use these to help designate memory of future submissions
EOF

done