screen -dmS s1 screen -S s1 -X screen screen -S s1 -X screen screen -S s1 -p0 -X stuff 'false'$'\n' screen -S s1 -p1 -X stuff 'read a; echo \$a'$'\n' screen -S s1 -p2 -X stuff 'hostname'$'\n' screen -r s1 -p0
This creates a screen session with 3 windows. How can I achieve that windows are exited automatically after successful command execution. In the above case only window 2 would be killed since hostname is the only command that successfully executes.