Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enter keyboard shortcuts in bash script

Tags:

bash

Is it possible to enter keyboard shortcuts into a bash script? For example, I have tried typing in ^d to substitute for control + d (logout) without success.

ubuntu@vfleet:~$ ^d
-bash: :s^d: substitution failed
ubuntu@vfleet:~$ ^D
-bash: :s^D: substitution failed

I am using screen to run a django development server in the background. One of the commands to run a particular screen as a daemon is control + a + d. The goal is to be able to enter in control + a + d into a bash script. For example:

python manage.py runserver
^a + d

Is this possible?

Edit: A valid method of avoiding the keyboard shortcut in screen is linked by Eric Renouf in the comments below. screen -d -m sh -c "python manage.py runserver" will start a development server as a daemon. This is a great solution for my particular problem, but it would still be nice to have a solution for the original question at hand.

like image 562
Peter Tao Avatar asked Jun 30 '17 12:06

Peter Tao


1 Answers

xdotool package is the solution here.

xdotool key ctrl+d

Full reference

like image 164
Benison Besra Avatar answered Oct 02 '22 23:10

Benison Besra