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

In my example, I am going to use the shell command "rake".

What is the lookup sequence Ubuntu uses to find what to do when rake is invoked? e.g. does it look for a path specified in .bash_profile, does it look some place else, etc.

share|improve this question
huh? you need to explain a bit more. Are you talking about "tab completion?" – Matt H Jul 14 '13 at 22:01
Im talking about environment variables, path environment variables, and whatever else the kernel does to find out what to do with a command @MattH – JohnMerlino Jul 14 '13 at 22:07
It is not the kernel, it's simply the shell (in your case, bash). Of course it does some system calls so the kernels is involved too but the shell is an userspace program (which means that it is not part of the kernel). – Benoît Legat Jul 14 '13 at 22:16
up vote 0 down vote accepted

I will assume you installed it through rvm. As you said, your PATH is modified by .bashrc or .bash_profile.

What the shell does is very simple, it looks at your command and splits it with the spaces and look for the first word (in you case, rake). Then it looks at the PATH environment variable (see its value with echo $PATH) which contains different directories separated by semicolons (:). It splits it with the semicolons and then iterate through every directory to see if there is a file that you have the rights to execute. When it finds it, the shell executes it giving the rest of the words as arguments.

In the case of rvm, you should have /home/username/.rvm/rubies/ruby-1.9.3-p374@global/bin in you PATH. It should find an executable called rake which then executes an executable called rake in /home/username/.rvm/gems/ruby-1.9.3-p374@global/gems/rake-10.0.3/bin which run /home/username/.rvm/gems/ruby-1.9.3-p374@global/gems/rake-10.0.3/lib/rake.rb (your version may vary).

share|improve this answer
Yeah this explanation is exactly what I was looking for – JohnMerlino Jul 14 '13 at 22:33

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.