1

How do I make a Shell Script that when doube-clicked automatically runs in the terminal? In other words: I am too lazy to constantly do

cd Desktop
chmod +x myscript.sh
./myscript.sh

, so is there any way to auto open the terminal for a bash script?

  • If you chmod +x a file, as long as the file system can store the data correctly (ie. a native file-system), the execute permission will be set, and double-clicking on the file will attempt execute. I just created a file.sh, chmod +x, then in my preferred pcmanfm-qt a double-click of it asks if I want to run in terminal (I answer yes & it runs). If i use thunar (my second favorite) it'll open in an editor -- using a different file manager may be all you need. (note: I'm using pcmanfm-qt & thunar as examples; I'm running Lubuntu, but also like Xubuntu - hence those choices) – guiverc Apr 26 '19 at 12:25
  • @guiverc What? I did chmod+x and it just opens the text editor. I have Ubuntu 18.04.1 LTS. – Axolotl101 Apr 26 '19 at 12:28
  • Using standard Ubuntu 18.04 LTS you'll likely be running GNOME & using nautilus, and it's doing what thunar did on my 19.04 box (opened in an editor; gedit probably in your case & it was something else in mine). I opened nautilus (Files it is called within gnome menus) & I didn't see any way to make nautilus do what you want (but I'm not a gnome person, so rarely use it & others may have ideas I've not discovered if you wait). My answer was to try another File.Manager/File.Browser. I tried dolphin and it too has a "Run in Konsole" option (Konsole is the KDE terminal) – guiverc Apr 26 '19 at 12:43

1 Answers1

0

You could create a launcher for the script. You would be able to run the script from the activities menu in GNOME (click it) and from the directory the file is saved in. This would be a .desktop file. e.g. Example.desktop:

[Desktop Entry]
Name=Example
Exec=/path/to/executable_script
StartupNotify=true
Terminal=true
Type=Application
Icon=/optional/path/to/icon.png

Make the file executable. When placed in /usr/share/applications or ~/.local/share/applications, GNOME will add the .desktop file to the activities menu.

Now you just have to click the launcher in the activities menu and your script will run. The terminal will close after the script has run to its end.

jeroen
  • 1,930