Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

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 have some script in my $HOME/bin folder. When I access my machine remotely I can't use them and I can't understand why. They work just fine when I'm in front of my remote computer.

I think it might have something to do with the .bashrc file. The PATH is set with

export PATH

it seems correct to me though.

I have also tried to copy the file in the /usr/bin folder logging out and in again, but still I can't manage to use my script.

If I go in the ~/bin directory and type ./myscript the script work (it is just that I need to run it from different folders where I have some files to process).

share|improve this question
Have you tried whether the PATH is really set? echo $PATH – user unknown Jun 6 '12 at 0:23
It just came to my mind.. and I came back to write that $PATH is actually not set. I couldn't read the answer 1 properly but my feeling is that it is the right one! – lucacerone Jun 6 '12 at 0:58
Is my answer the one you're having trouble reading? If so, please post comments to it, explaining the problem--I may be able to reply and/or edit my answer, for clarification. When you say $PATH is not actually set, do you mean that when you run echo $PATH, there is no output at all? – Eliah Kagan Jun 6 '12 at 1:02
Eliahs answer looks right to me too - my comment was just there to make a fast check. A fast solution will however be to source the desired *rc-file like . ~/.bashrc or source ~/.bashprofile – user unknown Jun 6 '12 at 1:05
up vote 3 down vote accepted

This is happening because when you log in via SSH, the shell you get is a login shell. In contrast, to use the terminology from the bash documentation, when you open a Terminal window in an already-started graphical login session, the shell you get is still an interactive shell but it is not a login shell.

From man bash:

When bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable. The --noprofile option may be used when the shell is started to inhibit this behavior.

When a login shell exits, bash reads and executes commands from the file ~/.bash_logout, if it exists.

When an interactive shell that is not a login shell is started, bash reads and executes commands from /etc/bash.bashrc and ~/.bashrc, if these files exist. This may be inhibited by using the --norc option. The --rcfile file option will force bash to read and execute commands from file instead of /etc/bash.bashrc and ~/.bashrc.

So you should check if you have any of these files:

  • ~/.bash_profile

  • ~/.bash_login

  • ~/.profile

If you do, then you should edit the first one you find and make it add $HOME/bin to your path. If you don't, create one of them for this purpose. (The best one to create is ~/.profile since other shells will use that too.)

You almost certainly have ~/.profile, since Ubuntu's default behavior is to create this with any new user account (including the first account, created when you install Ubuntu).

However, by default this file already contains the necessary lines to add your private bin directory to the $PATH:

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

So it's a bit strange that this is not already working for you.

Depending on your needs, you might want to make ~/.profile (or ~/.bash_login or ~/.bash_profile) call ~/.bashrc:

source ~/.bashrc

But it would be even better to just include lines adding $HOME/bin to your $PATH in ~/.profile (or ~/.bash_login or ~/.bash_profile), but not ~/.bashrc. After all, if you do this for every login shell, it should also happen when you log in graphically, and be inherited by all your interactive shells that aren't login shells.

share|improve this answer
Thanks Eliah it worked (copying .bashrc into .bash_profile ). I can't understand properly the distinction between login shell, bash --login and so on though. What are the differences between the two kind of sessions? And how do I know wich session is invoked? (ok for ssh now I know..) Thanks again, you made my day! – lucacerone Jun 6 '12 at 1:03
@LucaCerone I recommend asking about what the differences are, and how to know what kind of shell you're in, as a separate question. This way, the answer will be maximally useful to others. (If you do this, you should feel free to comment here with a link to the new question, of course.) – Eliah Kagan Jun 6 '12 at 2:55

Simply put your config in .bash_profile file in home directory.

If you dont have it you can create it.

share|improve this answer
If .profile exists, which it probably does, then having a .bash_profile file will override .profile, causing it not to be used. This can cause problems. So if you're going to create a .bash_profile when .profile already exists, then the .bash_profile should contain the line source ~/.profile, so that the commands in .profile are still run. Alternatively, just add the commands to .profile. – Eliah Kagan Jun 6 '12 at 0:51
Thanks Norton and Eliah for the useful advices! – lucacerone Jun 6 '12 at 1:07

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.