4

I have serveral customized environment variables and functions in my ~/.bash_profile which I would like to be called automatically when I start my screen session with screen -D -R, but apparently adding source ~/.bash_profile in ~/.screenrc doesn't solve my issue.

On every new screen I have to manually source the bash_profile.

I have noticed that this file can't be found while creating a new screen (when you create new screen there is the the line in the bottom showing what commands are executing and it returns that the file can't be found.)

Amir
  • 1,348
  • 3
  • 21
  • 44

2 Answers2

6

~/.bash_profile is only run by login shells.

~/.bashrc is run by other interactive shells, such as those started by screen.

~/.screenrc is a screen configuration file, and is not used to configure bash.

Put things that should be set up per shell in ~/.bashrc, and add source ~/.bashrc to your ~/.bash_profile.

that other guy
  • 116,971
  • 11
  • 170
  • 194
  • still the same issue, when opening a new screen I am receiving this thing: `.screenrc : source ~/.bashrc: No Such file or directory` – Amir Nov 26 '14 at 19:49
  • @Amir You seem to have modified `.screenrc` instead of `.bash_profile` as suggested here – that other guy Nov 26 '14 at 21:15
  • I did change the `~/.bashrc` as well, but just put that source so that it def runs it. – Amir Nov 26 '14 at 22:18
  • 1
    @Amir It doesn't do what you think it does. You should remove it. To see that this works, put `export MYTEST=foo` in your `.bashrc`, open a new screen window, and run `echo $MYTEST`. Make very sure not to confuse the three files. Do not add the export line to `.screenrc` or to `.bash_profile`, only `.bashrc`. – that other guy Nov 26 '14 at 22:42
4

You can try configuring screen to run a login-shell by default.

Screen runs a sub-shell, unless told otherwise (See "shell" .screenrc command). Example .screenrc entry to run a login-shell:

shell -$SHELL
Criveti Mihai
  • 321
  • 1
  • 3