I have 3 commands I want to run within a shell script within a GNU screen.
The following is the content from script.sh
.
counter=$((counter + 1))
screen -dmS $counter sh -c \
"command1;exec bash;\
python3 script2.py ${word};exec bash &&\
command3;exec bash"
When I run ./script.sh
. I want to run command1 first, then python3 script2. I only want to run command3 after python3 script2 is done.
I want to be able to open the screen and check on the python3 script2 process until it finishes that's why I'm doing it this way.
But I can see that command 1 and command 3 are being run simultaneously.
What's the right way to do this code?
Because there is "," between python3 script2.py ${word} and exec bash . it will execute exec bash without waiting for the completion of script2.
exec bash will complete immediately and invoke command 3 before the completion of script2
I have made following change
"command1 ; exec bash;\
python3 script2.py ${word} && exec bash ;\
command3;exec bash"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.