Here are already many questions like this, but every one recommends (a variant of) the following solution:
screen -dmS somename bash -c "/path/to/script; bash -l"
e.g. when the script ends, run an new bash.
Unfortunately, this isn't works for me, because
- the
scriptuses the $BASHPID variable for something - the
scriptruns runs forever, e.g. need terminate it with CTRL-C - and after the termination i must have the same shell as runs the
script(same$BASHPID)
So, the question is:
- How to start the
screenin detached mode (e.g. at boot) - normally this is done by the-dm - it must start the shell
- best, if it can start it as "login" shell, e.g. what reads my
.profile, but this can be overcome with thesource ~/.profilein thescriptitself - the
scriptstart some other (binary) program what will run till CTRL-C
- best, if it can start it as "login" shell, e.g. what reads my
- and after the termination of the
scriptI must get the samebash(with the same$BASHPID(because need run another scripts what's depends on it)
In short need simulate the following interactive work:
- start
screen echo $BASHPID- run-some-commands inside the screen (the last one runs until CTRL-C) - e.g. run the
/path/to/script - detach (ctrl-a d)
After the above, later, I can do
- reattach (
screen -ARR) - CTRL-C
- and can continue... with the same
echo $BASHPID#will produce the same as above
Any idea? (thinking about the -X but it not works, somewhere i probably making a mistake)
screen -L -dmS name bash --init-file <(echo "pwd;ls") (note the-Llogging) i got in thescreenlog.0the following:bash: /dev/fd/63: Bad file descriptor, and the commands aren't executed.(The child doesn't got the parent's redirection - the redirection is processed by the screen itself). Anyway, upvoting and accepting this, because it pointed me to the solution.--init-file /real/file/with/bash/commands` works nicely. Thank you. – clt60 May 25 '15 at 15:18