How do I ask screen to behave like a standard bash shell?

39,564

Solution 1

Thanks to this post, what I did was add one line to ~/.screenrc:

# ~/.screenrc
defshell -bash      # dash makes it a login shell

Then things in your ~/.bashrc, /etc/bashrc, etc. should get run.

Solution 2

screen changes the term-type to screen. You can do one of two things:

  1. change the term setting in your .screenrc
  2. modify your .bashrc files look for TERM=screen as well as TERM=xterm

Solution 3

I like the way you wrote your question, I was asking myself the same thing and it took a little while to figure it out. I was fortunate to already know a little about shell invocation, so I figured the problem lay there somewhere.

Here are my findings. Firstly, I personally find it interesting and worth knowing the difference between a login shell and a non-login shell. Do a man $SHELL and search for the section on INVOCATION to read more about it.

You can ask your current shell instance if its a login shell or non-login shell by issuing a shopt login_shell on your prompt. Note this is normally a read only option.

On my Debian systems, screen has always come defaulted with non-login shells.

After searching the web and reading man $SHELL, I tested a few things out and the following two approaches worked for me. In ~/.screenrc add/update a line as follows:

shell -$SHELL

If that doesn't work out AND you are using bash, you can alternatively try, as shared by Seamus:

defshell -bash

As mentioned, you can test if your current shell instance is a login shell by issuing shopt login_shell on your prompt.

Solution 4

Depending on how you're used to running Bash, you may be running a login shell. When you run screen, you're running a non-login interactive shell.

The difference is in which startup scripts are run.

  • /etc/bash.bashrc then ~/.bashrc are sourced when a non-login interactive shell is started

  • /etc/profile then the first found of ~/.bash_profile, ~/.bash_login, and ~/.profile are sourced when an interactive login shell is started

This may be affecting you.

I would also check to see if $TERM is different.

Solution 5

screen doesn't replace bash, it runs it, or any other shell. maybe it's running csh, zsh, or bash but with different paramters.

the first thing i would try is to check with ps and /proc/<pid>/cmdline to be sure that it's using the same shell with same parameters as login does.

after that, check /etc/screenrc and any other file mentioned at man screen FILES section.

Share:
39,564

Related videos on Youtube

thornomad
Author by

thornomad

Updated on September 17, 2022

Comments

  • thornomad
    thornomad over 1 year

    Just learned about the screen command on linux - it is genius. I love it. However, the actual terminal/prompt in screen looks and behaves differently than my standard bash prompt. That is, the colors aren't the same, tab completion doesn't seem to work, etc.

    Is there a way I can tell screen to behave just like a normal (at least, normal as in what I am used to) bash prompt ?

    Additional Information

    I am connecting via ssh from a Mac (Terminal) to a headless linux box (Ubuntu). After logging in, I have TERM=xterm-color and when I run screen I have TERM=screen.

    Am going to try the suggestions below to see if I can change the $TERM value first.

    • Zoredache
      Zoredache about 14 years
      Just out of curiosity what OS, and what type of terminal do you have when start screen? I would guess your issues has more to do with your Terminal doing something wrong or identifying incorrectly to screen.
    • thornomad
      thornomad about 14 years
      @Zoredache - I added that information to the post, above. Thanks. I did have to adjust my Terminal's settings to allow the backspace key to work ...
    • Zoredache
      Zoredache about 14 years
      Yuck, I really don't like Terminal.app. Personally I suggest you consider using an alternative see (serverfault.com/questions/19240/…)
  • thornomad
    thornomad about 14 years
    Thanks! I created a $HOME/.screenrc file and added this line to the top: term xterm-color and wa la! Color prompt and the $TERM values match. However, no tab-completion ...
  • thornomad
    thornomad about 14 years
    I ran a ps command and it shows that bash is running (this is a ps command inside of screen) ... I got the color working (above) just need tab completion.
  • hookedonwinter
    hookedonwinter about 14 years
    You need to dig into what turns the tab-completion on. The default shell configuration scripts are not entirely consistent about what they enable based on $TERM; some things will enable with xterm as well as xterm-color, others only look for xterm. Other things have other switches.
  • rudolph9
    rudolph9 over 6 years
    Is the way to have the shell launch in the current directory? An example of what I desire is the following cd ~/Projects ; screen ; pwd #=> ~/Projects. However, what I get after adding shell -$SHELL to my ~/.screenrc is cd ~/Projects ; screen ; pwd #=> ~/
  • Andy B
    Andy B over 3 years
    ^ This is the answer! Worked for me!
  • LHMathies
    LHMathies over 2 years
    Note that this will set your $SHELL to bash (no path). You can actually do shell -/bin/bash in your ~/.screenrc which will set $SHELL to /bin/bash -- that works better if a program tries to use execv on the value. (OpenSSH ProxyCommand, I'm looking at you). Also since you can't change this value dynamically, defshell and shell are the same.