![](/assets/images/image-default.png)
Run a Bash Script File by Double-Clicking
For a while I’ve been thinking that I would benefit from setting up a few bash script files that run upon double-clicking them, to automate a few daily tasks.
I have created Python executable files in the past with pyinstaller, but I think sometimes a simple bash script is all we need.
So today I decided to figure out how to do it. I just tested with a simple script that creates a directory in the folder where it is located. I leave the explanation below.
System
This method was tested in Linux Mint. It should also work in Ubuntu.
Example File
As an example, you can create a file test_file
with this content:
cd "`dirname "$0"`"
mkdir "dir created with double-click"
This script will create a folder called dir created with double-click
in the same directory of the test_file
.
The file extension is not the key. I purposely chose the example file name
test_file
without an extension.
File Permissions
It is necessary to change the permissions of the file to allow the execution of the file as a program. The command below would change the permissions for the file called test_file
.
chmod +x test_file
Alternatively, this can also be done through the UI: right-click the file, Properties > Permissions > Allos executing file as program.
File Explorer
After finishing the previous step, if we double click the file we will be able to run it after a confirmation dialog box (each time the file explorer will ask to confirm if we really want to run it).
If needed, this last step could be avoided by changing the preferences in the file explorer: Preferences > Behaviour > Executable Text Files > Run executable text files when they are opened.
It’s good to know that this last step could be avoided if necessary, but I think the best is to stick to the double-click plus confirmation - it seems more secure.