So how to send command to screen session from other terminal. In other words how to remote-control a screen session from within a script. This post is useful for this.
In particular, I wanted to execute matlab scripts in screen windows. To do this I used the following:
1. Create screen session
screen -S matlab
2. Create few windows in the screen session using Ctr-a c 3. Send matlab command to each as follows
for ((i=0;i<$NO_WINDOWS;i+=1)); do
echo $i
sleep 2
screen -S matlab -p $i -X exec matlab -nodesktop -r "bashCalculations('part',$i+1)"
done
where bashCalculations is my matlab script bashCalculations.m that takes part argument. So,, each screen window executes different part of my script.