I have a bunch of hand-rolled executable scripts in my $HOME/bin directory. Some are written in bash, some in Ruby. All of them have the shebang line at the top telling the shell what interpreter to use (bash or Ruby, in my case).

I'm wondering if it is better to put file extensions on these scripts to indicate what scripting language they are written in? For example, the scripts in Ruby would have the *.rb suffix, and the bash ones would have the *.sh suffix.

Currently, these scripts just have simple names with no file extension.

What's the best practice?

link|improve this question

It's easy enough to convert from shebang to extension and back with a simple script. So try one and fix it later if you need to. – Aaron J Lang yesterday
feedback

3 Answers

up vote 3 down vote accepted

You can't do wildcard commands like ls *.rb or cp *.sh if you want to organize your scripts in the future. Start early or regret later, IMO.

Editors like vim will also be able to apply the correct syntax highlighting based on the file extension.

link|improve this answer
1  
IMHO, organization is better done by function, not by details of implementation. – grawity Oct 7 '11 at 17:09
3  
@grawity: nevertheless is organizing by suffix simpler than grepping for shebang ... – akira Oct 7 '11 at 17:30
feedback

It's not necessary. The kernel is already informed of the correct interpreter to use (by the #! line), and all popular text editors read it as well, so adding an extension would do nothing useful, only increase typing. The only time an executable program has an extension is when it is somehow important (to the program or the user or both).


Modules and libraries, on the other hand, almost always have extensions (.rb for Ruby modules, .so for ELF shared libraries, and so on).

link|improve this answer
the question is not so much about 'is the kernel able to run it if i dont provide the suffix' but about 'does it help ME'. increase of typed chars is irrelevant with completion. – akira Oct 7 '11 at 17:33
feedback

Well - as most things in life: It depends on your needs.

You stated that these scripts reside in a bin-directory and I assume that these scripts are to be called from the command line. As user I consider it as annoying if I have to type bla.ksh or foo.bash. Also if the coder decides to move to annother interpreter the command name would change too and I would have to amend other scripts that make use of these tools - very annoying, even if user and coder are the very same person.

But on the other hand I use extensions like .sh or .tcl in my project build directories. This way I can make use of make features to deploy the files into their destination directories - but at this stage I remove the file suffix.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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