Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Can I write keyboard shortcut in bash script like:

#!bin/bash
echo Hello
^z # this is kbd shortcut

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

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

1 Answer 1

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

 
discard

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.