I have wrote some commands in a shell script to run some ROS commands to launch my robot. I recently got a control pad where I can bind certain buttons to some keybinds like Ctrl + 1 etc... I want to be able to bind my shell script to a key bind as well, so that I can launch my robot with the push of a button.

I added a shortcut to the keyboard settings on my Ubuntu 18.04 system. For the command section I put: ~/shell_scripts/robot_launch.sh The same command I run in my terminal to run the sh file. However, the shortcut does not work.

Is it possible to bind a key to a shell script?


1 Answer 1


Yes it's possible. In Gnome (and I believe other DE's as well) you have to use the full path of the script when asked:


~ is not expanded to your home directory, so the script can't be found

  • I am using Gnome. I went to settings > devices > keyboard > keyboard shortcuts and added a custom shortcut. I added the following as the command: "/home/nuc/shell_scripts/test.sh" and binded it to ctrl + 1, however it still does not work. test.sh is a shell script i wrote that just runs "pwd" my actual robot_launch.sh runs a bunch of roslaunch commands. The terminal output is not necessary. However, when I press run "ps" it shows that there is no roslaunch running in the background. Jun 2, 2022 at 16:22
  • @user528125 You have to make the script executable: chmod +x script. Though depending on what the script does the problem could be elsewhere. Jun 2, 2022 at 16:30
  • I have done that. The shell script runs perfectly when I run it in the terminal. If I change the script to one line: firefox "google.com" the script can be binded to a key. It looks like gnome keybinds allow me to launch apps. Even through shell scripts. Is it possible for me to run a sequence of commands in the terminal through a gnome keybind? My original idea was to write a shell script which runs a sequence of commands. And that shell script works perfectly, if i run it in the terminal. But it does not work when binded to a key. Jun 2, 2022 at 17:22
  • The issue has been resolved, the "~" was half the problem. The other half was that the script would need to be ran in a terminal. So a new script was created which launched a terminal and then ran my original script in it. That new script was then binded to my controller Jun 2, 2022 at 19:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .