I want to run a bash script in a detached screen. The script calls a program a few times, each of which takes too long to wait. My first thought was to simply open a screen and then call the script, but it appears that I can't detach (by ctrl-a d) while the script is running. So I did some research and found this instruction to replace the shebang with following:#!/usr/bin/screen -d -m -S screenName /bin/bashBut that doesn't work, either (the options are not recognized). Any suggestions? PS It occurs to me just now that screen -dmS name ./script.sh would probably work for my purposes, but I'm still curious about how to incorporate this into the script. Thank you.
Run script in a screen
shell script;scripting;gnu screen;shebang
The shebang line you've seen may work on some unix variants, but not on Linux. Linux's shebang lines are limited: you can only have one option. The whole string -d -m -S screenName /bin/bash is passed as a single option to screen, instead of being passed as different words.If you want to run a script inside screen and not mess around with multiple files or quoting, you can make the script a shell script which invokes screen if not already inside screen.#!/bin/shif [ -z $STY ]; then exec screen -dm -S screenName /bin/bash $0; fido_stuffmore_stuff