10

I'm running Ubuntu 14.04 (Cinnamon Mint 17.1) with Bash. Every time I open a new terminal window, I enter screen to start the screen window manager, but I would like the shell to do this for me.

I believe I need to modify .bashrc instead of .profile, so it starts on every new terminal window, not just on logon. So I've added the following to the end of .bashrc, to replace the shell process:

exec /usr/bin/screen -q

When I start a new terminal window:

  • Usually, I get a blank window with a flashing cursor, and the Bash prompt only appears after I press Ctrl+C.
  • Sometimes, the terminal window closes immediately, when I press Ctrl+C, or when I resize the terminal window.
  • Sometimes, I get a Bash prompt with no $LS_COLORS (though it's hard to reproduce this, so I'm not entirely sure when or why it happens).

Can anyone explain why this is failing for me, and suggest a solution?

Thanks,

Huw

Damien
  • 103
  • 5
Huw Walters
  • 243
  • 2
  • 9
  • You might wanna add a '&' to end of command. – We are Borg Sep 17 '15 at 08:59
  • Is running `screen` on top of `bash` a possibility? I.e. simply `screen -q`, I've always had problems on running commands on top of `gnome-terminal` directly, I'm pretty sure it has something to do with it. – kos Sep 17 '15 at 09:12
  • @kos: No, I already tried that. I get the same "blank screen with Bash prompt on `Ctrl+C`" behaviour, but then I can't close the terminal window with `Ctrl+D`. – Huw Walters Sep 17 '15 at 09:15
  • @WeareBorg: I get a Bash prompt with `Must be connected to a terminal.`, and `screen` does not start at all. – Huw Walters Sep 17 '15 at 09:17
  • This is the cowsay I have in bashrc which I have added, maybe it helps as I see fortune output everytime I open a new tab : http://pastebin.com/25fPSr8n – We are Borg Sep 17 '15 at 09:19
  • Ubuntu 14.04 != Cinnamon Mint 17.1 – DK Bose Sep 17 '15 at 10:10
  • @DKBose: No, I realise that. The one is built on top of the other. Just trying to provide as much information as possible. – Huw Walters Sep 17 '15 at 10:30
  • @WeareBorg: Thanks, though I'm not really sure how that helps; a simple `echo Hello world` in my `.bashrc` also produces output on every new terminal, but `screen` still behaves weirdly. )-: – Huw Walters Sep 17 '15 at 11:51
  • Maybe you would want to contact screen developers, they will have more luck. Good luck! The intention of pastebin was to show how I have put a console based program to start everytime a new tab is opened or terminal is opened. :-) – We are Borg Sep 17 '15 at 11:57

1 Answers1

11

When screen starts, the first window launches your shell, and you've told your shell to start screen. Then, when screen starts, the first window launches your shell, and you've told your shell to start screen. Then, when screen starts ...

Lather, rinse, repeat.

screen sets the $TERM variable to "screen", so to avoid endlessly recursive invocations of screen ("turtles all the way down") your .bashrc can end with:

[[ $TERM != "screen" ]] && exec screen -q
glenn jackman
  • 17,625
  • 2
  • 37
  • 60
  • 2
    Just in case someone is trying to replicate this in Ubuntu 16.04 with the default terminal: add this to your .bashrc `[[ $TERM != "screen.xterm-256color" ]] && exec screen -q` – bluppfisk Feb 03 '18 at 02:42
  • 3
    To check with what value you have to compare `$TERM`, run screen and type `echo $TERM` before editing `.bashrc`. – Pierre Aug 26 '19 at 07:29
  • Definitely more robust to call exec screen -q on exact value of '$TERM` before you start screen like: ``[[ $TERM = "xterm-256color" ]] && exec screen -q`` – tonylo Sep 16 '21 at 18:23