I have a machine configured (via cron) to start a screen session on reboot. The session opens up a few screens and starts a server in one of them. All of this works fine. However, when I login and resume the screen session, I get a (PS1) prompt like this:

\u@\h [\j] \w\$ 

Terminal colors do not appear either. This is the PS1 string I explicitly set in my bashrc file, but the control sequences like \u are not being interpreted by the shell. I have ensured that my bashrc and profile get imported before the screen starts; the script called from cron:

#! /bin/bash
# This script initializes screen with a propert environment. It is intended to
# be run from cron.

# source the profile
if [ -r "$HOME/.profile" ]; then source "$HOME/.profile"; fi
if [ -r "$HOME/.bash_profile" ]; then source "$HOME/.bash_profile"; fi
if [ -r "$HOME/.bashrc" ]; then source "$HOME/.bashrc"; fi

exec screen -dmS initscreen

I tried adding the line "export TERM=screen.xterm-256color" and variants (e.g., export TERM=xterm-256color), but these changed nothing.

My assumption is that because there is not a real TTY when the screen gets started at reboot, somehow screen can't interpret my terminal correctly and ends up starting up without any terminal interpretation. When I quit screen and rerun the startup script from an ssh session (instead of from cron at reboot), everything work fine. How can I get screen to startup at reboot in a way that will let me attach it later with these terminal features working?

Thanks in advance.

  • I thought I had this issue covered because there was a shell $SHELL line in my .screenrc file... but of course it hadn't occurred to me that cron might not use my shell. Changing this to shell /bin/bash fixed the issue. Thanks! If you want to write this as an answer I'd be glad to accept it.
    – nben
    Commented May 2, 2020 at 5:13

1 Answer 1


The fact that magic characters like \w in PS1 are not being interpreted seems to suggest that the shell started by screen is not bash, but something simple like /bin/sh. I looked at /etc/crontab in one of the systems I had to hand and it had the line


at the start, but another distribution had SHELL=/bin/bash, so you probably need to set this explicitly somewhere to ensure you get a consistent result.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .