I cannot run the above script using sh scriptName, but I can run it using bash scriptName. Hence, naming the file scriptName.sh might lead to some confusion.
You are way more pedantic than I am, which is certainly not a bad thing. All my .sh files have the shell defined one the first line, like in your example. As long as they are executable, one can run them with scriptName without knowing the shell, so to me there is nothing confusing. I don't use bash anyway :)
By the way, slurm doesn't care at all about file extension, and neither do Unix/Linux shells. All my slurm jobs end in .job.
Using
somefile_slurmwill make it explicit that it is a SLURM script rather than a pure shell script, without having to open the file to see what is in it.Note: I have not tested to see if SLURM needs the
.shextension when doingsbatch somefile_SLURM.shor if it will happy withsbatch somefile_SLURM, if you want to follow @Ram's suggestion.Would
sbatch <(head somefile.txt)work?Update:
sbatchis happy with just a file name..shis not required.Thanks. So I have different types of shells: C shell (#!/bin/csh); BASH (#!/bin/bash); Korn shell (#!/bin/ksh) etc... But BASH does not need a suffix like .sh or .csh. (Should it be .bash?)
You use SLURM to interact with HPC to run your script (written in BASH or Bourne Shell (.sh)). You can mark that is a SLURM script also (human convention) if you want to. Is this right?
Maybe is a naive question but how do I choose what kind of shell to use? On my personal computer I have bash by default, but also sh, rbash and a few others are installed.
For my script to work I have to make sure that the shell type is installed?
Please do not add an answer unless you're answering the top-level question. Use
Add CommentandAdd Replyinstead.Suffixes are not needed for any type of file. It's for human convenience and other conventions (such as Windows and macOS automatic program associations). Imagine having to remember what type each file is and choosing a program to open it with every time - that is the pain avoided by having automatic program associations based on filename extensions/suffixes.
My statement is not to be interpreted as "each shell gets it own file extension". It is to be interpreted as "there is a chance for confusion if
shis both a shell and a file extension that is not specific to theshshell." This only matters becauseshonly has a subset ofbash-like features.That is correct.
This is a matter of personal preference. Most of us use
bash. I used bash for years before switching tozsha few years ago. A lot of smaller HPC systems don't havezsh, sobashmight be the safer bet.Not if you stick to bash - that is almost universally available. You're just starting out, so keep an eye out for when you stumble into shell-specific features.