Terminal not sourcing .bashrc

versatile 64-bit multi-user Linux distribution

Moderators: kirk, jamesbond, p310don, JakeSFR, step, Forum moderators

Post Reply
sfein1000
Posts: 96
Joined: Fri Mar 25, 2022 1:38 am
Been thanked: 4 times

Terminal not sourcing .bashrc

Post by sfein1000 »

I created a .bashrc in /root (right now it just has a new exported PS1 value). When I open a new terminal, it does not appear that it is being sourced or used at all. Does a new terminal automatically source .bashrc? I tried killing X (using ctrl-alt-backspace), manually sourced .basrc from the terminal and then ran xwin. But new terminal windows still do not show anything from .bashrc. If I source using:
source ~/.bashrc
or
. ~/.bashrc

the current terminal shows the new PS1, but not new terminals.

User avatar
JakeSFR
Posts: 277
Joined: Wed Jul 15, 2020 2:23 pm
Been thanked: 159 times

Re: Terminal not sourcing .bashrc

Post by JakeSFR »

I think it's because the default shell for root is not /bin/bash, but /bin/sh (which is a symlink to bash, but still).

Try .shinit instead, it works for me.

Or change the shell to bash using chsh --shell /bin/bash root and re-login with wmexit logout.

Greetings!

[O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource
Omnia mea mecum porto.
williams2
Posts: 1065
Joined: Sat Jul 25, 2020 5:45 pm
Been thanked: 306 times

Re: Terminal not sourcing .bashrc

Post by williams2 »

Typing bash in a terminal will execute (source) $HOME/.bashrc

Typing sh in a terminal will not execute (source) $HOME/.bashrc

Typing sh -l in a terminal will execute (source) $HOME/.profile

Typing bash -l in a terminal will execute (source) $HOME/.profile

You need to read the documentation to know exactly what file is automatically sourced and when.

and when to use aliases and when to use shell functions.
and when to use export

step
Posts: 550
Joined: Thu Aug 13, 2020 9:55 am
Has thanked: 58 times
Been thanked: 198 times
Contact:

Re: Terminal not sourcing .bashrc

Post by step »

To add to what others before me wrote, Fatdog doesn't read $HOME/profile. Instead it reads $HOME/.fatdog/profile. If you don't have directory .fatdog, just make it then create your profile file in it. This is a good place to add environment variables that should be shared across all instances of the shell (all terminals). All shells (sh, bash, zsh, ksh, ...) read this file, so avoid "shellisms" like bashisms in it. This file is read once when the login session starts.

$HOME/.shinit
# /etc/shinit invokes $HOME/.shinit for each interactive ash / dash / sh instance (not bash, fish, zsh).
# /etc/shinit is invoked because environment variable ENV=/etc/shinit
# even though /bin/sh links to /bin/bash, /bin/sh doesn't invoke $HOME/.bashrc

$HOME/.bashrc
# $HOME/.bash_profile invokes $HOME/.bashrc
# bashrc is for non-login shells (terminals); it's invoked even when the shell isn't interactive

sfein1000
Posts: 96
Joined: Fri Mar 25, 2022 1:38 am
Been thanked: 4 times

Re: Terminal not sourcing .bashrc

Post by sfein1000 »

Thanks for all of the replies. Putting my code in $HOME/.shinit worked.

Post Reply

Return to “FatDog64”