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 am under the impression that if I include the line


at the start of my file, it will be recognized as a bash script that I can run just by

instead of


But in my case, gives something like gives command not found. Why is that?


I notice I need to use ./. But I thought it will look in the current directory anyway?

share|improve this question
Did you include \#!/bin/bash in your file as you write? There shouldn't be a backslash in the beginning. – N.N. Aug 13 '11 at 13:15
Nono thats a typo ... also see update – Jiew Meng Aug 13 '11 at 13:49
No, it doesn't work in the current directory unless, the current directory is in your PATH. You can edit your PATH to always include the current directory ., but it is not recommended. – frabjous Aug 13 '11 at 13:54
sh and ./ are not equal if the first line is #!/bin/bash! The correct way to execute bash scripts is by using bash Also, using the .sh extension is discouraged because of the confusion ("it says .sh, so I must use sh right?") – Lekensteyn Aug 13 '11 at 13:59
up vote 12 down vote accepted

First you need to make sure the file is executable:

chmod +x

And then to run it, you either need to put it in your PATH, i.e., one of the directories of files the OS searches when looking for files to run, which you can find with echo $PATH, or else you need to type in:


Rather than just type

You can just type, if it's in your PATH, which I recommend. A good place is in ~/bin. Create that folder if it's not there, and under Ubuntu, it'll get added to your path when you log in.

share|improve this answer

You need to start it with ./, because the current dir is not in the PATH.

If this isn't sufficient, becaused you missed, what frabjous suggests, to chmod a+x, you should start programs beginning with a shebang #!/bin/bash with




even if sh is a symbolic link to /bin/bash.

The shell checks how it was invoked, and can be invoked as sh to act in a compatible mode, therefore it can fail to handle some bashisms, which would work if invoked as bash

That was not your problem, but might become one, if you don't know these subtle distinction.

share|improve this answer

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.