Fork me on GitHub

Naming Shell Scripts

You're writing a shell script to do... something. Whatever it is, it will hopefully make your life easier in some way or other.

But what do you call it?

This touches on a pet peeve of mine. Whatever you do, do not call it somescript.sh. You should never use the extension .sh for your scripts. Never ever in a million years.

Why?

Because this means that whenever you need to invoke the script, you need to invoke somescript.sh. I know - it is only 3 characters more, so why does it matter?

It matters because it hilights to the world that this is a shell script. It exposes an implementation detail which should not be exposed.

If your script is nice (is well documented and has a nice interface etc) then you will end up with other scripts calling your scripts. If you publish your script, then others might write scripts that call yours. And you will never know.

Then one day when you decide that "this is better done in Python" (or whatever language is in fashion at that time), you will end up with a Python script named somescript.sh. The alternative is to break backward compatibility (and possibly upset a lot of people) and rename it to somescript.py. All because you didn't think ahead (or didn't care about your users).

Any script you write should not be thought of as "a script". You should be thinking "I am creating a new command". Imagine how you want the command to look and behave. The fact that your new command is implemented in whatever scripting language you choose is irrelevant to the users of your new command.

As a counter-example: Imagine if you had to call ls.EXE instead of ls, sh.bin instead of sh etc. The world would be a horrible place. Your new command should make the world a better place; not a worse place.

Please think of your users. They will care about what the new command does - just like you care about what ls does. And you didn't really care whether junit was a script or not. Your users won't care whether your new thing is either.