Thursday, January 26, 2012

Aliases in Screen

What a headache!
GNU Screen on Cygwin was not getting my aliases. Searching all over the internet yields that screen runs ~/.bashrc since it is not a “login shell”. This was not happening. Everybody says to add shell -$SHELL to run an interactive shell and that will source your ~/.bash_profile which will usually source ~/.bashrc (as is my case). Now this works, but it does not explain why my ~/.bashrc is not running without shell -$SHELL. What does the documentation say?
shell command
Set the command to be used to create a new shell. This overrides the value of the environment variable $SHELL.
So what is my $SHELL variable set to?
$ echo $SHELL
/bin/bash
But if I run /bin/bash and run alias, all my aliases are there. Clearly screen is not doing what it says. So is that it? The documentation is just plain wrong? When I add shell $SHELL (notice the absence of the ‘-‘) my aliases do show up. But if shell _command_ “overrides the value of the environment variable $SHELL” wouldn’t shell $SHELL do nothing? Yet it does. It fixes my problem. Screen runs ~/.bashrc where it otherwise does not.
In summary:
  • with nothing in ~/.screenrc: neither ~/.bashrc nor ~/.bash_profile run
  • shell $SHELL: only ~/.bashrc is run (non-login shell)
  • shell -$SHELL: ~/.bash_profile is run, which typically also sources ~/.bashrc (login shell)
  • the GNU screen documentation is wrong. Or at least, unclear.

No comments:

Post a Comment