Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

This question already has an answer here:

I am learning to write shell script from this tutorial on linuxcommand.org. It says -

Most modern Linux distributions encourage a practice in which each user has a specific directory for the programs he/she personally uses. This directory is called bin and is a subdirectory of your home directory.

I've tried this. But I get the following error-

foobar: command not found

Later in that page, it also says that-

On some distributions, most notably Ubuntu, you will need to open a new terminal session before your newly created bin directory will be recognised.

It means that ubuntu does support this feature. But why isn't it working?

I am on Ubuntu 12.04 LTS.

share|improve this question

marked as duplicate by Mateo_, Eric Carvalho, AgentCool, Basharat Sialvi, Thomas W. Apr 24 '13 at 4:53

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

4  
Did you copy your foobar script to /bin? –  green7 Apr 23 '13 at 16:21
    
Also, make sure the script is executable, and called foobar, not foobar.sh –  jackweirdy Apr 23 '13 at 16:24
1  
@Hennes Please take a look at this link to learn some basic tricks to format your comments quickly. –  green7 Apr 23 '13 at 16:32
    
Without the backticks the helpful parser makes the http:// part invisible. Not sure how to work around that without typing it twice. :( –  Hennes Apr 23 '13 at 16:40
    
@Hennes This is the result of your link: What are “$PATH” and “~/bin”? How can I have personal scripts? And it seems to be a duplicated. –  Lucio Apr 23 '13 at 21:18

1 Answer 1

When you log in or start a new shell then some scripts get parsed. Exactly which scripts depend on which shell you use (e.g. ksh, csh, tsch, bash, dash, pinosh, ...) and if it is a log-in shell or not.

If you are using Ubuntu's defaults then it is likely that it will contain this:

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH"
fi

In other words, if ~/bin/ already exists, then add it to the search path.
If it does not exists then there is no reason to try to search that location every time. So do not add it.

This means that you will have to create ~/bin/ and then start a new shell, or create it and manually add a path to it.


As to "Most modern Linux distributions encourage". This was already encouraged in 1991 when I got my first unix account on a server running ESIX. Still true today though.

share|improve this answer
    
That code snippet isn't present in ~/.bashrc or /etc/bash.bashrc by default; is there somewhere else you've found this? –  jackweirdy Apr 23 '13 at 17:06
    
In my Ubuntu 12.10 VM it is in the last four lines of ~/.profile (but not in /root/.profile) –  Hennes Apr 23 '13 at 17:14

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