To begin with, if it worked for you when you eliminated the shebang (ie, the #! / bin / bash) it is because:
Your Linux distro is wrong
You are not in any Linux distro.
1) If your Linux distro is wrong, you can run the following on your terminal.
$command -v bash #Para que te muestre lo que entiente tu terminal por "bash"
#Puedes copiar esa ruta y ponerla en el shebang.
$cat /etc/shells #Si no estás seguro de tener bash (lo cual sería rarísimo en tu distro)
#Puedes ver qué otros interpretes de comandos tienes con este comando.
You can also run the script with "source", ".", "bash", "sh". And see which of these runs. "source" and "." they are synonymous and they load the content of a file in the terminal in which you are, instead, "bash" is the program that you should have in the path "/ bin / bash" and "sh" is a symbolic link to "/ bin / dash ".
Keeping in mind that you can do something like $source tu_script
2) In case you are not in a Linux distribution (which seems because the error you copied and hit speaks of "batch file"), install an emulator (In case you want to play with bash to scriptear ). You can install:
Since you install it, there should be no problem with that script.
I would just run it with:
$bash tu_script
$sh tu_script
For which the shebang is not necessary. On the other hand, if you want to run it with the shebang, first make it executable with chmod +x tu_script
and then run the program with:
$./tu_script #o en su defecto.
$/ruta/completa/a/tu_script
The other is that maybe you do not need to create a file for bash, but for bat (if that is a batch processing file) and that same file put the extension .bat, you put a "pause" at the end of the code, you eliminate the shebang and should run.
Although perhaps the best thing (only as a suggestion) is that the next one you indicate since SO, console / terminal you are running it.
Regarding the shebang, it is related to the operation of the so-called magic numbers.
Here is information about the shebang:
link
And here about the magic numbers:
link
But in summary, they allow a user to run a program "as if it were" a binary, read the program that describes the shebang and run the content of the program based on the program that is described, it can be bash, python, cat, awk, ruby, any of the Unix world. And it allows you to identify it, for example, when you have a program "tu_script" with the shebang "#! / Bin / bash" and you ask the command file tu_script
to tell you what kind of program it is, it returns something of type:
$file tu_script
tu_script: Bourne-Again shell script, ASCII text executable