I want to set custom PS1 and PATH variables, but on which startup files?

OS : Fedora Workstation 34
Shell : bash

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.


Thank You Tim.

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 :point_down:

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 :point_down:

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 ?

1 Like

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.

1 Like

you may create ~/.bashrc_guislaine, and use an include at the end of .bashrc like

if [ -f ~/.bashrc_ghislaine ]; then
. ~/.bashrc_ghislaine

and in .bashrc_ghislaine: etc…

if [ “$UID” -ne “$ROOT_UID” ]
PS0=‘\033[4m\033[37m$HOSTNAME:$USER:$PWD %$LINENO\033[0m \n’
PS0=‘\033[4m\033[41mROOT: $HOSTNAME:$USER:$PWD %$LINENO\033[0m \n’

do the same in /root etc…


1 Like