2

I have a script 'myscript.sh', that calls a vendor script 'vendorscript.sh'. The vendor script runs screen in the foreground.

I would like to run the vendor script with screen detached. If possible I would like to do this without hacking the vendorscript.sh or vendor_screenrc.

Is there a way to do this?

myscript.sh:

# some other commands
...
source vendorscript.sh

vendorscript.sh:

# some other commands
...
exec screen -c vendor_screenrc
2

If vendorscript.sh does not use an absolute path to launch the screen program, you could try manipulating the $PATH prior to execution. This also assumes that the $PATH is not reset/manipulated within vendorscript.sh.

For example, I've created a directory /opt/vendor and created a shell script in it called screen:

#!/bin/bash
exec /usr/bin/screen -d -m "$@"

And in myscript.sh:

#!/bin/bash
PATH="/opt/vendor:$PATH"
source vendorscript.sh

Because /opt/vendor is first in the $PATH, the vendorscript.sh will use my wrapper script instead of the screen binary. According to man 1 screen:

-d -m Start screen in "detached" mode. This creates a new session but doesn't attach to it. This is useful for system startup scripts.

And the "$@" passes through the remaining arguments from the original invocation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.