#create a screen with session name cli screen -S cli now detach, and let's control it entirely from another terminal scr="screen -S cli" #create a second window $scr -X screen #and a third $scr -X screen #select the first $scr -X select 0 #split into two regions $scr -X split #focus on the lower one $scr -X focus down #select the second window in this lower region $scr -X select 1 #clear window 0, leaving lower region showing window 1 and remaining current $scr -p 0 -X clear #greet window 0 $scr -p 0 -X exec echo hallo #ssh to localhost in window 0 $scr -p 0 -X exec ssh localhost #the exec hasn't returned #simulate typing ls\n $scr -p 0 -X register 1 "ls " $scr -p 0 -X paste 1 #that effectively ran ls on the remote host #exit from the ssh connection $scr -p 0 -X register 1 "exit " $scr -p 0 -X paste 1 #kill all three windows, terminating screen $scr -p 2 -X kill $scr -p 1 -X kill $scr -p 0 -X kill