I have a code of python in lets say test.py. I need to run it using Slurm in a remote location. Thats why I am trying to make a .sh file.
In Putty, I am doing these:
touch main.sh
echo #!/bin/bash > main.sh
....
echo #SBATCH --gres=gpu:1 >> main.sh
....
echo python3 train.py >> main.sh
Then I make it executable with
chmod u+x main.sh
And I try to run it with
bash main.sh
But I am getting this error:
sbatch: error: This does not look like a batch script. The first
sbatch: error: line must start with #! followed by the path to an interpreter.
sbatch: error: For instance: #!/bin/sh
As I try to check
file main.sh
I am getting
main.sh: ASCII text
I am a novice in bash. So I cant understand what the issue is. Can someone help?
#is the shell comment marker, so the commandecho #!/bin/bash > main.shis treated asechowith the comment#!/bin/bash > main.sh... and of course the comment part is ignored. So you need to quote or escape the#. Depending on what shell you're using and what mode it's in,!may also be a special character (even in double-quotes!). So it's safest to just single-quote the entire string.echo #!/bin/bashwill write, when invoked on the command line, #!/bin/bash to stdout, while when invoked in a script (or configured differently), the same statement will just output a newline character. Google for interactive comments to get more insight in this thema.