You are not logged in.

#1 2025-11-01 03:38:07

mr_kaddy
Member
Registered: 2025-10-24
Posts: 12

[SOLVED] Where is my default PS1 set?

I want to figure out where is the current $PS1 used by default on a new installation being initialized.

[kaddy@192 ~]$ echo $PS1
[\u@\h \W]\$

To check for it, I visited the usual suspects. I don't have a ~/.bashrc and my ~/.profile is empty. So, I check out /etc/bash.bashrc. The only relevant code it contains is:

# Prevent doublesourcing
if [[ -z "${BASHRCSOURCED}" ]] ; then
  BASHRCSOURCED="Y"
  # the check is bash's default value
  [[ "$PS1" = '\s-\v\$ ' ]] && PS1='[\u@\h \W]\$ '
  case ${TERM} in
    Eterm*|alacritty*|aterm*|foot*|gnome*|konsole*|kterm*|putty*|rxvt*|tmux*|xterm*)
      PROMPT_COMMAND+=('printf "\033]0;%s@%s:%s\007" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/\~}"')
      ;;
    screen*)
      PROMPT_COMMAND+=('printf "\033_%s@%s:%s\033\\" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/\~}"')
      ;;
  esac
fi

Here, it is checking for $PS1's value but not setting it, which means that $PS1 was set even before this. In /etc/profile, the relevant code is:

if test "$BASH" &&\
   test "$PS1" &&\
   test -z "$POSIXLY_CORRECT" &&\
   test "${0#-}" != sh &&\
   test -r /etc/bash.bashrc
then
	. /etc/bash.bashrc
fi

Even here, it checks whether $PS1 is initialized already but doesn't initialize it in this script. I can't find any sourced script which is run even before /etc/profile.

So where is my current $PS1 even being set? Note that I know that in case I wish to change it, I can modify ~/.bashrc or ~/.profile, but my aim here is to first understand where is it even being set.

Last edited by mr_kaddy (2025-11-01 23:13:36)

Offline

#2 2025-11-01 05:48:36

patrick4370
Member
From: Australia
Registered: 2018-07-19
Posts: 4

Re: [SOLVED] Where is my default PS1 set?

Have a look at /etc/skel/.bashrc

I'm certain it is being set there.

Offline

#3 2025-11-01 06:19:09

ahepp
Member
Registered: 2025-10-27
Posts: 14

Re: [SOLVED] Where is my default PS1 set?

[root@arch ~]# grep -r PS1 /etc
/etc/profile:   test "$PS1" &&\
/etc/bash.bashrc:  [[ "$PS1" = '\s-\v\$ ' ]] && PS1='[\u@\h \W]\$ '
/etc/skel/.bashrc:PS1='[\u@\h \W]\$ '

/etc/skel is used for templates (the "skeleton") when creating new users. In case you weren't convinced bash was reading /etc/bash.bashrc:

[root@arch ~]# pacman -S strace
[root@arch ~]# strace -e openat /bin/bash
openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/usr/lib/libreadline.so.8", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/usr/lib/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/usr/lib/libncursesw.so.6", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/dev/tty", O_RDWR|O_NONBLOCK) = 3
openat(AT_FDCWD, "/usr/lib/locale/locale-archive", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/usr/lib/gconv/gconv-modules.cache", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/usr/lib/gconv/gconv-modules", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/usr/lib/gconv/gconv-modules.d", O_RDONLY|O_NONBLOCK|O_CLOEXEC|O_DIRECTORY) = 3
openat(AT_FDCWD, "/usr/lib/gconv/gconv-modules.d/gconv-modules-extra.conf", O_RDONLY|O_CLOEXEC) = 4
openat(AT_FDCWD, "/etc/nsswitch.conf", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/etc/passwd", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/usr/share/terminfo/v/vt220", O_RDONLY) = 3
openat(AT_FDCWD, "/usr/share/locale/locale.alias", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/usr/share/locale/en_US.UTF-8/LC_MESSAGES/bash.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/usr/share/locale/en_US.utf8/LC_MESSAGES/bash.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/usr/share/locale/en_US/LC_MESSAGES/bash.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/usr/share/locale/en.UTF-8/LC_MESSAGES/bash.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/usr/share/locale/en.utf8/LC_MESSAGES/bash.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/usr/share/locale/en/LC_MESSAGES/bash.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/etc/bash.bashrc", O_RDONLY) = 3
openat(AT_FDCWD, "/root/.bashrc", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/root/.bash_history", O_RDONLY) = 3
openat(AT_FDCWD, "/root/.bash_history", O_RDONLY) = 3
openat(AT_FDCWD, "/root/.inputrc", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/etc/inputrc", O_RDONLY) = 3
[root@arch ~]# exit
exit
openat(AT_FDCWD, "/root/.bash_history", O_WRONLY|O_APPEND) = 3
openat(AT_FDCWD, "/root/.bash_history", O_RDONLY) = 3
+++ exited with 0 +++

A lot of rc files that exist in your home directory, have analogous files in /etc with global configuration information.

Offline

#4 2025-11-01 08:51:02

seth
Member
From: Don't DM me only for attention
Registered: 2012-09-03
Posts: 70,964

Re: [SOLVED] Where is my default PS1 set?

Here, it is checking for $PS1's value but not setting it

# the check is bash's default value
[[ "$PS1" = '\s-\v\$ ' ]] && PS1='[\u@\h \W]\$ '

is the same as

# the check is bash's default value
if [[ "$PS1" = '\s-\v\$ ' ]]; then
   PS1='[\u@\h \W]\$ '
fi

You can wrap it in "set -x" and "set +x" to see what's actually done here when executing the script

Offline

#5 2025-11-01 23:13:15

mr_kaddy
Member
Registered: 2025-10-24
Posts: 12

Re: [SOLVED] Where is my default PS1 set?

patrick4370 wrote:

Have a look at /etc/skel/.bashrc

I'm certain it is being set there.

Thanks a lot! I did not know about the existence of these skel files. PS1 is indeed being set over here. Thanks a lot! Thanks to @seth for the clarification and @ahepp for the pretty detailed explanation of what happens when a new Bash shell is spawned.

Offline

Board footer

Powered by FluxBB