Bash files with Github asked:

I’ve never saved any of my bash scripts with an extension and I’ve just recently pushed a bash script to Github and realized that it’s not properly highlighting the correct syntax such as: comments, variables, loops, etc. Github has even tagged the script as a Javascript file and isn’t reading the directive #!/bin/bash. How can I resolve this issue and ensure my script is properly interpreted as a Bash script on Github?

My answer:

Github looks for the shebang interpreter directive. This is the line at the top of the file which specifies what interpreter should be used to run the script.

An example of such a directive is:


Github will highlight scripts containing such a directive, as well as those with a .sh extension (and a few others).

Your example script was identified correctly by github, but it was highlighted incorrectly. This suggests that you’ve somehow triggered a bug in their parser, linguist. This is something I would contact the linguist developers about.

View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.