4

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.

guntbert
  • 13,134

1 Answers1

3

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.

Hennes
  • 1,233
  • 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