Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question

closed as off topic by EEAA, mdpc, Andrew, Jenny D, Tom O'Connor May 14 '13 at 9:59

Questions on Server Fault are expected to relate to professional server, networking, or related infrastructure administration within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

add comment

2 Answers

up vote 1 down vote accepted

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:

#!/bin/bash

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.

share|improve this answer
    
Ive specified this at the top of my script, this is really all I should need for Github to determine that it's a script written in Bash. I still can't crack why it's not reading this properly. –  Dford.py May 13 '13 at 23:38
    
Got an example? –  Michael Hampton May 13 '13 at 23:41
    
    
Hmm. Presuming you don't have something silly in that script like a BOM, I think you've discovered a bug in github's linguist. –  Michael Hampton May 13 '13 at 23:51
    
I'm not even aware of what that is exactly, I've looked through to see if I've made any mistake and haven't been able to spot anything unusual. I've looked other bash scripts on Github and theirs works just fine with #!/bin/bash directive. Strange... –  Dford.py May 13 '13 at 23:55
show 1 more comment

Looking at the source code for GitHub's "linguist" [1] it needs to have a .sh extension [2]

We use this library at GitHub to detect blob languages, highlight code, ignore binary files, suppress generated files in diffs and generate language breakdown graphs.

(Emphasis added by me)

[1] https://github.com/github/linguist

[2] https://github.com/github/linguist/blob/master/lib/linguist/languages.yml#L1190

share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.