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.

5
  • 4
    Did you copy your foobar script to /bin?
    – green
    Commented Apr 23, 2013 at 16:21
  • Also, make sure the script is executable, and called foobar, not foobar.sh
    – jackweirdy
    Commented Apr 23, 2013 at 16:24
  • 1
    @Hennes Please take a look at this link to learn some basic tricks to format your comments quickly.
    – green
    Commented Apr 23, 2013 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
    Commented Apr 23, 2013 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
    Commented Apr 23, 2013 at 21:18

1 Answer 1

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.

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

Not the answer you're looking for? Browse other questions tagged .