Run a Shell Script with double click on Ubuntu

Asked

Viewed 8,609 times

1

I have a program in Shell, it does the installation and configuration of some programs on Ubuntu, I wanted to know how to compile or make it run when the user double click on it, yesterday had found a program in C that does this, but I lost the code and could not find it anymorelo.

  • To make a shell script executable use chmod, example: chmod +x arquivoShell.sh

  • yes the question was how to run the shell by double-clicking the file. sh because even with +x it does not run

  • ma got it, I’ll post the answer

  • Okay. I posted an answer anyway.

  • Please correct the errors in the code, close the parenthesis, and still present this error: syntax error close to the token' não esperado void'

3 answers

6

No Ubuntu 15.04:

Open Nautilus and click the Edit menu then Preferences. In the window that opens, click the Behavior tab and mark one of the options indicated by the arrows.

inserir a descrição da imagem aqui

Also, your file needs to be with execution permission. It can be granted via command line:

chmod +x arquivoShell.sh

or via Nautilus. For this case, right-click on the desired file and select Properties option.

inserir a descrição da imagem aqui

  • It doesn’t work like that, I had tried this method, yesterday I was going to post the answer, but I was logged in by cell phone so it’s really bad.

  • @Leonardovilarinho, strange, because in my Ubuntu works and I’ve done it in several versions. It must be something different that you’re trying to do. Anyway, I find too much to have to make an application in C to run a shell-script with double-click.

3

You can do this by creating a file with the .desktop. You must give permission to execute by clicking on properties and ticking the appropriate checkbox. (see image of the answer above). Note that in the Icon option you can specify any valid image file (do your tests), in my example, will appear the icon of a folder. Must be coded as UTF-8.

I discovered this on my own, but found some related articles desktop-file and How to create launchers shortcuts on desktop.

Script:

#!/usr/bin/env xdg-open
[Desktop Entry]
Name=teste
Comment=Programinha para teste
TryExec=/home/helcio/Programas/exemplo
Exec=/home/helcio/Programas/exemplo
Icon=folder
Terminal=true
Type=Application

1


Well an easy way that I found as I had already said, was to create a C program that runs the script and open the terminal.

Code in C: (main. c)

#include<stdio.h>
#include<stdlib.h>

main(void)
{
    system("gnome-terminal --command '/opt/shell.sh'");
}

And then in compilation with:

gcc -o executal main.c

Then put it on the desktop and shell.sh on /opt

Browser other questions tagged

You are not signed in. Login or sign up in order to post.