LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   ~/.bashrc, /etc/bash.bashrc files not read? (https://www.linuxquestions.org/questions/slackware-14/%7E-bashrc-etc-bash-bashrc-files-not-read-4175490071/)

Tachtory 01-03-2014 10:55 PM

~/.bashrc, /etc/bash.bashrc files not read?
 
Trying to set permanent changes to the bash prompt in Slackware 14.

On my linux mint the colors are set in /etc/bash.bashrc

Reading the doc /usr/doc/Linux-HOWTOs/Bash-Prompt-HOWTO seems to suggest that prompt settings should be set in ~/.bashrc

I created the following .bashrc file but it does not seem to be read when logging in:

Code:

if [[ ${EUID} == 0 ]] ; then
    PS1="\[\033[01;31m\]\u@\h\[\033[01;34m\] \w \$\[\033[00m\]"
else
    PS1="\[\033[01;32m\]\u@\h\[\033[01;34m\] \w \$\[\033[00m\]"
fi

As far as I can tell there aren't any syntax errors with the assignment to PS1; if I set PS1 from the command line to one of the two prompts it works and shows up with color. I also tried without the if/clause and also tried moving the file to /etc/bash.bashrc but still no change in the prompt.

astrogeek 01-03-2014 11:19 PM

Your login is not loading the ~/.bashrc...

Slackware does not add (many) things not included in the upstream packages, and that includes the optional config files for bash added by some other distros.

For the order and precedence of bash configs, as always, see man bash (INVOCATION section).

But to get you going here is a quick summary:

Quote:

When bash is invoked as an interactive login shell, or as a non-interactive shell with the --login
option, it first reads and executes commands from the file /etc/profile, if that file exists. After
reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads
and executes commands from the first one that exists and is readable. The --noprofile option may be
used when the shell is started to inhibit this behavior.
So ~/.bashrc is not read when it is your login shell. Typically you will want to create a ~./bash_profile with the following lines:

Code:

if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

Additionally, if you have system wide bash aliases or vars, put them in /etc/bashrc and add this to your ~/.bashrc:

Code:

if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi

That will give you a fairly common bash config stack, and load your ~/.bashrc.

Tachtory 01-04-2014 12:17 AM

Thank you! It was that missing .bash_profile. I see also I must create files in the /root/ directory too if I want a custom root prompt.

astrogeek 01-04-2014 12:25 AM

Quote:

Originally Posted by Tachtory (Post 5091663)
Thank you! It was that missing .bash_profile. I see also I must create files in the /root/ directory too if I want a custom root prompt.

Great! Yes, you have to add the bash configs for all users, including root.

If you have multiple users on the system you might want to create the .bash_profile and .bashrc in /etc/skel/ when you first install, then any users you create will get their own copy.


All times are GMT -5. The time now is 07:20 AM.