Ubuntu: Simulate Enter Press in a Screen



Question:

I have successfully run command

screen -S Run -X stuff 'stop'`echo -ne '\015'`   

in the terminal and had screen Run receive the stop command and then receive the simulated enter press. This results in the program running in that screen terminating. However when I try to make a script which looks like this

#!/bin/sh    screen -S Run -X stuff 'stop'`echo -ne '\015'`  

the screen revives the text

-X: stuff: invalid option stop-ne  

I would like to know what is wrong with my script and how to correct it so screen Run receives the stop command and then receives an enter press


Solution:1

The sh version of echo does not support options.

Change your script to be run with Bash like so:

#!/bin/bash  screen -S Run -X stuff 'stop'"$(echo -ne '\015')"  

Alternatively, just put a literal newline in the string instead of relying on echo:

#!/bin/sh  screen -S Run -X stuff 'stop  '  


Solution:2

try:

screen -S Run -X stuff 'stop^M'  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »