10

I am not so into Linux and I have the following doubt following a tutorial.

I have to modify the bashrc file. What kind of settings are contained in this file? I think something related the bash shell environment but I am not so sure about it.

I have to insert this line:

export PATH=$HOME/.local/bin:$HOME/.local/usr/bin:$PATH

What exactly does this line?

I think that export statement is used to create a new variable making it available for other program.

But what exactly does this line? Is PATH the name of the variable that I am defining? What is $HOME?

What means the : symbol between PATH=$HOME/.local/bin and $HOME/.local/usr/bin and $PATH section in the previous expression?

What exactly does this expression mean?

4
  • The : between the items is the separator for each segment. Without it, your path would be one continuous run on and would not work.
    – Terrance
    Oct 6, 2016 at 17:35
  • In Ubuntu this kind of PATH modifications is already done in the ~/.profile file, so it's a little inconsistent to do similar stuff in ~/.bashrc. Better IMO to modify the code already in ~/.profile if needed. Currently the default ~/.profile file includes this line: PATH="$HOME/bin:$HOME/.local/bin:$PATH" Oct 6, 2016 at 19:41
  • @GunnarHjalmarsson: There are some situations that make .profile and .bashrc different. The file .profile is parsed by login shells and not by subshells. But since you need to login anyway to start a subshell this is OK since subshells will inherit $PATH. The .bashrc file will not be parsed by the login shell but will be parsed by subshells. The difference comes when you have some stuff that are not children of login shells (maybe some fancy automation script that calls other scripts like git commit hook) - anything in .profile will not be read so they will be ignored
    – slebetman
    Oct 7, 2016 at 6:57
  • @slebetman: Right, and in case of a desktop there is another difference which you don't mention: Unlike ~/.bashrc, ~/.profile is sourced by the display manager, so only variables set by ~/.profile are available when you start programs from the graphical environment. And that happens early so it should be ok for autostarted processes for the session. Oct 7, 2016 at 9:43

2 Answers 2

17

To recap everything mentioned in this question,

The export part

The export line means that the variable that you declare after it will be accessible to child processes. In other words, processes will be able to access the variable declared after the export keyword through the shell's environment. So, if you did something like export FOO="BAR" and then sourced the changes in your shell environment, you could type $FOO and get BAR.

The PATH part

The path line is just as you stated: it's declaring a variable that's named PATH for the shell environment. In the bash environment, PATH has a special purpose of defining where the computer looks for programs is. This lets you type custom commands for scripts without typing the full directory. Note that PATH is marked for export by default, so this line doesn't have to be rewritten. It doesn't hurt, though.

The $HOME in the PATH variable

At the beginning of the path that is assigned to the PATH variable, $HOME is declared. This means that the computer will pretty much grab the value stored in HOME and copy-paste it in front of the rest of the line when reading it.

The : in between both paths

The : is equivalent to a comma in sentences. It just separates the three directories. Without those three directories, the console would not recognize the commands it receives. Those three places are the three directories that are most commonly used for scripts/command files to be stored and therefore should be accessible by the terminal without having to write out the full path to the file.

1
  • Great answer! "The export line means that the variable that you declare after it will be accessible to child processes" is the parent for these child processes the terminal from where I will run a command ?
    – vadasambar
    Jul 23, 2019 at 14:58
6

The PATH variable lets bash know where to look for executable programs, so if you have a script or some other executable file in $HOME/.local/bin , modifying PATH will let you type and run that file just like you do with ls or df.

export only means to make that PATH variable also available for other programs you run from bash.

As for : , it's just a separator for each directory. It's the same as a comma in a list of words, nothing more.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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