2

The command . .bash_profile is used to reload(?) bash_profile. What is the general purpose of the first .? How it can be used and is there a resource to read about these type symbols of Terminal?

1
9

The command . is a shell built-in. It executes the shell script you give as argument, but within your current shell environment. This is also called "sourcing" a script. In Bash, source is therefore a synonym of . (but e.g. not in sh or in the POSIX standard). Also see What is the difference between "source" and "."?

Sourcing a script (like . ~/.bashrc) is different to regularly running a script (like ~/.bashrc) in that if you run it normally, it will run inside a sub-shell instead of the current shell environment.

A sub-shell has its own working directory, shell options and local variables, so that changing them within the script (e.g. by using cd or setting/changing variables) does not affect the parent shell. If you run a script, it will also only get read access to those local variables of the parent shell which it exported, not the regular ones.

If you want to allow the script to modify your current environment (e.g. to change shell options, set environment variables, create aliases and functions which you then can use, etc), which is the case for .bashrc, you have to source it. If you just ran it, all its changes would be lost as soon as it exits and returns to your shell environment.

More info can be obtained by running help . or help source, and man bash (section about shell built-ins).

1
  • I thought . and source would have been duplicate by now but I couldn't find one. So +1 :) – WinEunuuchs2Unix Jun 10 '18 at 14:54

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