Page 1 of 1

Terminal not sourcing .bashrc

Posted: Fri May 06, 2022 9:06 pm
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.


Re: Terminal not sourcing .bashrc

Posted: Fri May 06, 2022 9:44 pm
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!


Re: Terminal not sourcing .bashrc

Posted: Fri May 06, 2022 10:01 pm
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


Re: Terminal not sourcing .bashrc

Posted: Sat May 07, 2022 5:26 am
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


Re: Terminal not sourcing .bashrc

Posted: Sat May 07, 2022 3:52 pm
by sfein1000

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