I found a PS1 variable which I would like to set to make my bash prompt more neat.
And I need to set a custom PATH variable in my bash shell.
So, every time I log into the gnome-terminal (bash), I need my custom PS1 and PATH variables to be set.
My PC has only 1 *custom user (ghislaine), so I looked at my home directory /home/ghislaine.
I see.bash_profile and .bashrc startup files in the home directory. But I do not see the .profile which I remember seeing in Solaris/AIX and may be enterprise Linux distributions like RHEL, Oracle Linux, etc
[ghislaine@localhost ~]$ ls -ld .b*
-rw-------. 1 ghislaine ghislaine 22426 Jun 3 22:20 .bash_history
-rw-r--r--. 1 ghislaine ghislaine 18 Feb 16 2019 .bash_logout
-rw-r--r--. 1 ghislaine ghislaine 155 Jun 3 23:00 .bash_profile
-rw-r--r--. 1 ghislaine ghislaine 488 Apr 6 22:34 .bashrc
[ghislaine@localhost ~]$
[ghislaine@localhost ~]$
[ghislaine@localhost ~]$ ls -l .profile
ls: cannot access '.profile': No such file or directory
[ghislaine@localhost ~]$
So, in Fedora, what is the recommended/neat way to set a custom PS1 and PATH variable for my user ?
*By custom user, I mean the user that is manually created at the end of Fedora installation and granted the sudo privilege.
First, you need to know that there are login shells and interactive shells. Which profile is used depends on which type of shell is started.
The best explanation is probably to run âman bashâ and read the section INVOCATION, which thoroughly describes which profile is used. I hope this helps.
Good to know about login, non-login, interactive, non-interactive shells.
I looked at the man page of bash as youâve recommended. This is what I understand
Stage1 - Logging in from GUI
My Fedora PC will not be accessed remotely via SSH and I will be logging in via the GUI window which prompts for the username and password. And If I am not mistaken, Fedoraâs GUI window prompts only for password in the regular use.
As I understand, this will be classified under interactive shell, although this is not done via a terminal and I assume the following applies in this GUI login. Screenshot of man page of bash > INVOCATIONS section
So, I can place my PATH variable in ~/.bash_profile so that it will be âavailableâ to all subshells right after my GUI login.
Stage2 - Invoking a gnome-terminal after login
As I understand, a gnome-terminal I invoke manually after my GUI login can be classified under interactive non-login shell.
So, the following applies in this case. Screenshot of man page of bash > INVOCATIONS section
So, I can place my custom PS1 variable in ~/.bashrc
I guess, if I place my custom PS1 variable in ~/.bash_profile, it will take effect for both âInteractive shellâ (Stage 1 mentioned above), then interactive non-login shell invocations (Stage2 mentione above) and the remote SSH connections. Am I right ?
That sounds about right to me. Now that you know how you think they should work, assign some dummy variables in the various profiles, and test them to make sure. But use different variables in different profiles so you know for sure where they came from.
E.g., in .bash_profile, put something like "XYZ = âThis was assigned from .bash_profileâ. Then start a shell and type âecho $XYZâ. And so on.