21

When I open a new window in GNU screen, it runs .bashrc but not .bash_profile. In my setup, this results in some environment variables not being set up correctly in that window.

How can I tell GNU screen to always run .bash_profile instead of .bashrc on opening a new window? (Please don't tell me to just call .bash_profile from my .bashrc :)

user9474
  • 2,448
  • 2
  • 25
  • 26

2 Answers2

35

You want to start bash (or whatever shell) as a login shell. You do this with

shell -$SHELL

in your ~/.screenrc. The magic is the - before the shell. See man screenrc for details. (Well, not many more details, because that's pretty much it.)

mattdm
  • 6,600
  • 1
  • 26
  • 48
  • 1
    When I do this it stops screen starting in the directory I use the command from. How can I make screen use the directory I launch the command from as the directory it starts up in? – theonlygusti Feb 09 '17 at 11:34
  • I don't get that manpage! The online docs are here though: https://www.gnu.org/software/screen/manual/screen.html#Shell. I got confused initially as the screenrc is only reread when a screen gets recreated - not each time you make a new window within the application – JonnyRaa Oct 05 '17 at 13:03
  • @theonlygusti For me, the working directory is preserved when setting up .screenrc as suggested. – Holger Brandl Jul 15 '19 at 13:31
  • Is there a way to tell screen to source a SPECIFIC rc file? I am on a shared system, and am new to a team of 35. They are used to their very customized .bashrc && .bash_profile files, and I have a file named .mybash.rc that I can simply "source ~/mybash.rc" every single time I create a new window in screen, but I wish I didn't have to do this every time. Is there a way to have this done from my screenrc? – PyTis Aug 25 '22 at 05:25
2

You would either need to source ~/.bash_profile from ~/.bashrc or put the things you need directly into ~/.bashrc or put the things in common in a third file and source it from both your ~/.bashrc and ~/.bash_profile.

Dennis Williamson
  • 62,149
  • 16
  • 116
  • 151