How to Configure Ubuntu to Run Shell Scripts When Double-Clicked

In Ubuntu, if you want a Shell script file to run directly when double-clicked instead of simply opening in a text editor, you need to confirm two things: the script itself has execute permission, and the file manager allows executable text files to be run.

1. Add Execute Permission to the Script

First, make sure the first line of the script has the correct interpreter declaration, for example:

#!/bin/bash

Then add execute permission to the script in the terminal:

chmod +x your-script.sh

You can also right-click the script file in the file manager, choose “Properties,” and under “Permissions” check “Allow executing file as program.”

2. Change the File Manager Settings

Open a folder, click Home Folder in the upper-left corner, and then go to Preferences.

%%LAZYBLOG_INLINE_0%%

In the Behavior tab, find how executable text files are handled and set it to run scripts. The wording may vary slightly between different Ubuntu / Nautilus versions. Common options include:

  • Run executable text files when they are opened: run executable text files directly when double-clicked.
  • Ask each time: ask whether to run the file or display its contents each time it is double-clicked.
  • View executable text files when they are opened: open the file in a text editor when double-clicked.

For a safer option, choose Ask each time. If you definitely want scripts to run on double-click, choose Run executable text files when they are opened.

Configure it as shown below:

%%LAZYBLOG_INLINE_0%%

3. Test the Script

You can create a simple script to test it:

#!/bin/bash
notify-send "Shell script is running"

After saving it as test.sh, run:

chmod +x test.sh

Then double-click it in the file manager. If everything is configured correctly, the system will run the script and show a notification.

If double-clicking still only opens the text editor, check again that the script has execute permission and that the file manager’s behavior setting for “executable text files” has been saved.

Leave a Reply