- All right.
We have been talking about many Bash features.
Some of these Bash features need to be provided
as a standard solution while you boot.
And that is why we have the Bash startup files.
To start with, Bash defines that you can use
etc environment to contain a list of variables.
And this etc environment is the first file
that is processed while starting a Bash shell.
Notice that using etc environment is not mandatory
so you might miss it on your distribution,
which is the case on Red Hat.
Red Hat and family doesn't use etc environment.
Then we have etc profile.
Etc profile is very important startup script.
It is executed while users are logging in.
An etc profile works
with drop in directly etc profile dot D.
So in etc profile dot D you can enter any script
that will be included as a part of the etc profile.
And users can have their specific etc profile as well.
And that makes sense, because sometimes
you want to make sure that the setting
is only available for a specific user,
not for everybody.
Well, in that case, you make sure
that the user has a Bash underscore profile
and that will be processed
anytime the user is logging in.
And you can even create a logout file.
Dot Bash underscore logout.
That is where you are going to process
when a user logs out.
Logs out, that means that the user is typing exit
from a current shell session.
And the Bash underscore logout is an awesome command to
take care of cleanup, for instance.
Now closely related to etc profile is etc Bash RC.
Etc Bash RC is processed every time a subshell is started.
It can have a user specific dot Bash RC as well.
And you might wonder why do we need two files?
Why is one not enough?
Well, that is because in a login shell where
the user first authorizes and authenticates
you might want to do different things than
in a subshell where we already know about these users.
And that is why there is two of them. But you will notice
that on many Linux distributions, they are kind of the same.
Now let me demonstrate how this works
and how we can use them.
So I'm starting with pseudo vim etc profile.
Strictly, you don't really need pseudo to read file
but it's making it a little bit easier
if you want to modify.
And there, we can see shell scripting code.
This is shell scripting code, and I can only
tell you one thing about it.
Don't touch it.
Don't change it.
Even if there's a parameter where you think, hey
I want to change that, you better don't change it here
because etc profile is managed.
It's a managed file, so it might
get updated automatically.
Let me do a pseudo LS on etc profile dot D.
And there we can see the drop in files.
These are shell scripts and these shell scripts are edited
to, as in addition to etc profile.
So if I wanted to change my Bash history file size
for everybody, I can use pseudo vim etc profile dot D
slash history dot SH. The file needs to end in SH
and in case you're wondering
what is this dot CSH? Well dot CSH is for the C shell.
That's a different shell that is not very
commonly used anymore.
So I'm just using SH to define a Bash include,
in which I use
export HISTSIZE is 2,500
and export
HISTFILESIZE is 5,000 for instance.
And there we go.
Now, the thing is that I just changed
my history dot SH.
Do you think that is automatically going to work?
Well, I can tell you a secret.
It's not because this is etc profile and etc profile
is all about logging in.
So if I use my HISTSIZE
variable to check what we've got
we can see my, HISTSIZE is currently set to 1,000.
There are two ways to make sure
that the new settings are going to be effective.
One way is to log out, log in again.
The other way is kind of a shortcut
and that is where you are going to use source.
Source on etc profile dot D slash history dot SH.
And now, if I use my echo HISTSIZE again,
there you go set to 2,500.
Which is by the way, pretty useful if you are
planning to use a lot of complex commands
and you wanna be able to find them again
even a year from now.
Right, let me have a look at one more file.
And that is what you can put in your home directory.
So Bash profile. And what is that doing?
Well, this is shell scripting code.
And in this shell scripting code, we are using a
IF statement to test, if we have a file
with the name dot Bash RC.
Now, what are we going to do?
We are going to read the file dot Bash RC.
And that is just to illustrate that Bash profile
and Bash RC are pretty close to one another.
So what do we have in Bash RC?
Well, in Bash RC, we have all this stuff that is
for this specific user.
So if this specific user needs to have a variable
export color is blue, for instance.
You put it in the Bash RC. Bash RC is for subshells.
So I am going to use Bash
and I'm going to use echo dollar color
and we can see it's becoming effective immediately
because my color is set to blue.
And that is how you can use these different
Bash startup files.