Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Can I write keyboard shortcut in bash script like:

echo Hello
^z # this is kbd shortcut

This didn't work. Is there any other way?

share|improve this question
ctrl+z in terminal means to stop running application, that is default. – nickanor Jan 8 '13 at 16:48
up vote 2 down vote accepted

It depends on what you want to do. Since you've used ^Z as an example, I assume you're trying to start some command and have it run in the background. Try adding an & at the end of the command instead:

sleep 5 && echo Hello &

That will set the command to run in the background as a sub-shell and will let your script continue - in this case, it would wait 5 seconds then print the word "Hello". When typed manually in a terminal, it will display the process ID.

Most other terminal keyboard shortcuts should have script equivalents, but some may not. Add them to your question if you want to use other shortcuts as well.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.