File extensions for unix shell scripts

I would only call .sh something that is meant to be portable (and hopefully is portable).

Otherwise I think it's just better to hide the language. The careful reader will find it in the shebang line anyway. (In practice, .bash or .zsh, etc… suffixes are rarely used.)


I would say that no "good practices" for file extensions exist, strictly on a technicality: Unix/Linux/*BSD file systems don't support extensions per se. What you are calling an extension is merely a suffix of a single file name. That's different than the VM/CMS, VMS, MS-DOS and Windows file systems and OSes where a special spot in the inode-moral-equivalent is reserved for an extension.

That little rant now over, I think it's a bit silly to put a ".sh" or ".ksh" or ".bash" suffix on a shell script file name. A program is a program: no benefit exists in distinguishing what gets executed. No unix or linux or whatever kernel has decided to call an interpreter on some file just because of a file name suffix. It's all done by the #! line, or some other "magic number" sequence of bytes at the beginning of the file. In fact, deciding what to execute based on a file name "extension" is one of the factors that makes Windows a malware magnet. Look at how many Windows malware scams involve a file named "something.jpg.exe" - by default newer Windows don't show the ".exe" extension, and encourage a user to just double click on the "image". Instead of an image view running, the malware runs.

What you might think of as a straight-ahead command is often a shell script anyway. Sometimes cc has been a sh-script, firefox is an sh-script, startx is an sh-script. I don't believe there's a cognitive or organizational benefit to marking a script with a ".sh" suffix.


As one who has worked in a multitude of ?nix environments, I have had to write in a wide variety of shells. Believe it or not, across platforms, the shells are not the same. So if you maintain your personal library in multiple shells (when necessary) it is very helpful to use extensions to ID the shells. That way when you move to another platform and the shell is slightly different, you know what scripts to target for modifications. .sh .ksh .bsh .csh ...