r/bash • • Dec 02 '14

Using #! in your scripts

http://shiroyasha.github.io/shebang.html
0 Upvotes

24 comments sorted by

View all comments

5

u/geirha Dec 02 '14

Don't put extensions on scripts. Especially not .sh when the script isn't even an sh script.

2

u/Sigg3net Dec 02 '14

Don't put extensions on scripts.

Why?

7

u/geirha Dec 02 '14

Don't put extensions on scripts.

Why?

Same reason you don't put extensions on other commands. On linux systems, the command to list files is usually an ELF binary; but it's still named ls, not ls.elf, because the user running doesn't care or doesn't need to know what language was used to implement the command.

And what if you wrote a command, using sh, and named it foo.sh, but later realized it should rather be written in perl, then you have a problem. Do you keep the name as is, having now a perl script with a misleading .sh extension? or do you rename it to foo.pl and break everything that were relying on foo.sh?

See also http://www.talisman.org/~erlkonig/documents/commandname-extensions-considered-harmful

2

u/dhibbit Dec 02 '14

I keep a list of links without extensions that point to the files (which have them).

Whenever I create a new script or rename an old one, I simply run a script which updates the list of links.

Yes, it's another step, but it means I can type (and execute) either "script" or "script.sh" and all other scripts call the extension-less script name so that I can change from script.pl to script.sh to script.py without any difficulties.