". ./filename.sh " why . space is required?

[email protected]

New Member
I am new user in this forum. I would like to know the file system command. Basically we are run the file using "./filename.extension" but some of the file require
". ./filename.extension" so why ".space" is required to run those files.

1. Export $PATH command write in shell file.


Well-Known Member
Using . ./script.sh will execute the commands in script.sh in the current shell. So any changes to things like environment variables (like $PATH) will affect the currently running shells environment.

Whereas if you run ./script.sh - the commands are ran in a sub-shell and any changes to environment variables are localised to the sub-shell the script was running in.

The . command is a bash builtin. To see some additional information about it, try the command:
help .
One practical use of the . command would be if you have made some changes to your .bashrc and you want the new changes to be applied to an older terminal session that was opened before you edited your .bashrc file.

Your .bashrc file is automatically loaded once whenever a new shell/terminal is first opened. But it never gets reloaded.
So if you open a terminal and make changes to your .bashrc - you will almost certainly want to use the . command to apply those changes to the terminal you are already in.

So for example - perhaps you have added some new aliases to your .bashrc, or you decided to use vi-style keyboard shortcuts instead of the default emacs style shortcuts. And now you want to have those settings applied to the current shell/terminal session (which was opened BEFORE you changed your .bashrc).

To apply the new .bashrc settings to the current terminal session you would use the command:
. ~/.bashrc
And that would cause the commands in your .bashrc to be re-loaded and ran in the current terminal/shell. And any recent changes that you've made in your .bashrc will then be reflected in the current shell/terminal sessions environment.

And you would have to do that for any other terminals/shells that were open BEFORE you changed your .bashrc.

So if you had three shells/terminals running before you edited your .bashrc and then you open a fourth terminal AFTER editing .bashrc - only the fourth terminal will be using the newest settings from .bashrc. So again - in order to apply the new settings to the other three open terminal sessions - you would need to run the . ~/.bashrc command in each of them, in order to reload your .bashrc and apply your changes to the execution environments of each of those shells.

Does that make sense?

Members online