Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have some functional scripts and I want to copy to /usr/bin I want to use them as normal terminal commands. Is it a good practice to use them with the .sh extension or can I save them without extension?

share|improve this question
Are you going to distribute them? – muru Jul 26 '14 at 22:52
No, it's for my own use. – Patterson Jul 26 '14 at 23:00
Also if you want those scripts to be available to all users, /usr/local/bin may be a better choice. – Salem Jul 26 '14 at 23:02
@Salem /usr/bin and /usr/local/bin should both be available to all users, but /usr/local/bin is better for executables that are not part of packages. – gerrit Jul 27 '14 at 1:13
@rath I get syntax highlighting without the extension if I have the shebang set to #!/usr/bin/env bash or #!/bin/bash. – Sparhawk Jul 27 '14 at 5:54
up vote 50 down vote accepted

No, it is not a good practice, you should keep your scripts without extension. Note, that scripts being part of packages doesn't have a .sh extension, i.e. update-grub, not If you are still not convinced, then be advised, that Google Shell Style Guide says:

Executables should have no extension (strongly preferred) or a .sh extension. Libraries must have a .sh extension and should not be executable.

PS You don't have to put your script into /bin. You can create directory ~/bin and put your script there. Directory ~/bin is included in $PATH by default, so scripts put there can be run as any other shell command.

share|improve this answer
"Directory ~/bin is included in $PATH by default" - Since when? Anyway, ~/.local/bin is probably a better choice as it's a standard. – nyuszika7h Jul 27 '14 at 11:07
You mean "Libraries must have a .so extension", right? Not sh. – Keith Wolters Jul 27 '14 at 13:39
@KeithWolters first, not me, but Google. Second, .sh, not .so, we are talking about shell scripts, not binaries. – user280493 Jul 27 '14 at 14:00
The Google style guide is very specific to Google. For example, "Bash is the only shell scripting language permitted for executables." Clearly an internal rule rather than best practices. – Paul Draper Dec 8 '14 at 8:33
@PaulDraper Note, that scripts being part of packages doesn't have a .sh extension, i.e. update-grub, not – user280493 Dec 8 '14 at 11:42

I second the recommendation to use ~/bin which gets automatically added to your $PATH,as Sergey said. Or /usr/local/bin, which may already be on the PATH. However:

  • You are doing this for yourself. Use whatever you feel comfortable with. Indeed, I'd say keep the extension so that you'll be reminded it's your script you are running, since -
  • Extensions are uncommon in /usr/bin. In my system, I can find only two:

    $ dpkg -S `ls /usr/bin/*.sh`
    mtools: /usr/bin/
    gettext-base: /usr/bin/

    So if you are packaging, definitely leave out the extension.

share|improve this answer
~/bin is added to the $PATH automatically if it exists, no need to add it manually. Just create the directory, log out and log back in. – Sergey Jul 29 '14 at 21:03

Just put following line at top of file:


So-that file will be automatically type : Shell Script without any extension!

Remember to give execution permission to file.

For putting script so-that can be run by direct command, visit: Where should I put my script so that I can run it by a direct command?

share|improve this answer
Or even just #!/bin/sh if you don't need the full bash shell. – flickerfly Jul 29 '14 at 21:16

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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