How to create screen session on startup with command that doesn't end when command finishes


Two ways. Either invoke a shell to run the script, which then replaces itself (using the exec builtin) with an interactive shell when the script is done

screen -dmS test bash -c '~/tmp/; exec bash'

or keep your current screen command and put exec bash in your script.

node ~/dev/mouser/app.js
exec bash

(On a side note, there's no point in having an extension on a script. It will just give you dependency headaches later if you rewrite it in another language. If you look in /bin and /usr/bin, you'll find a lot of sh, bash and python scripts; none of which have a .sh, .bash or .py extension)


Related videos on Youtube

Csabi Vidó
Author by

Csabi Vidó

This is my AskUbuntu profile and most of my stuff here on StackExchange is tech-oriented. However I do have other hobbies and interests, you may find more about these in my other profiles on the network. I'm lwbt on Reddit and Telegram. I started with Ubuntu and Linux somewhere between 2006 and 2007. With the release of 08.04 I completely migrated away from Windows to Ubuntu and while this has been a few years ago I still consider myself fairly new to this topic and I know I can still discover something new and exciting everyday. The following listing is not to brag about hardware, I'm rather trying to reproduce issues and share experience. Custom built desktop computers with Intel HD graphics (dualscreen setup), Lenovo T530 & T560 (touch) without discrete graphics (also run Windows 10), Chromebooks Lenovo N22 & ASUS Flip C302 (with GalliumOS) Behringer FCA610 USB (PulseAudio multichannel configuration), JDS Labs C5D & The Element, Bluetooth dongles and BT audio speakers and headphones Wacom Intuos 4 PTK-540WL HP 3005pr Port Replicator (works with proprietary DisplayLink driver) Aten CS1794 HDMI KVMP Switch Logitech TK820 and some unifying receiver mice …and some APC UPS

Updated on September 18, 2022


  • Csabi Vidó
    Csabi Vidó 5 months

    I want to edit my rc.local file to start up a few server sessions each in it's own GNU screen. However, whenever I stop a server, the screen terminates.

    Currently I have:

    screen -dmS test ~/tmp/

    with this inside

    node ~/dev/mouser/app.js

    How do I get the screen to stay alive after the passed in command or script terminates?