Executable text file

Solved
jojomisterjo Posted messages 646 Status Member -  
mamiemando Posted messages 33228 Registration date   Status Moderator Last intervention   -
Good evening community,

Here is a question that bothers me: when I make a text file executable (on Ubuntu), it asks for confirmation to run the script (the choices are: Run in terminal - Display - Cancel - Run).

I have to click on "Run in terminal" to run the script.
How can I bypass this execution request so that the executable text file runs with just a click?

Thank you

1 answer

  1. mamiemando Posted messages 33228 Registration date   Status Moderator Last intervention   7 940
     
    You just need to double click on it and the file must have execute permissions.

    chmod a+x /path/to/the/file


    If you run your script as is, any messages that would have been displayed in the console are not shown anywhere, but the script is indeed launched. To convince yourself, you can very well write a script pouet.sh that does something like:

    #!/bin/sh echo `date` > ~/pouet.txt 


    Run this script from your file explorer and you'll see that the file pouet.txt has indeed been created in your home directory.

    If you absolutely want a script a.sh to be launched in a terminal, you need to write a file go.sh that launches a terminal (for example, an xterm) and calls pouet.sh in that terminal (assuming that is possible).

    In fact, it's a bad idea because you cannot guarantee that your script will execute correctly on all machines. Typically in go.sh, you would invoke an xterm in which you launch pouet.sh, go.sh will crash on machines that do not have xterm installed. Generally speaking, you cannot guarantee that a user has installed any particular type of terminal (if they do not have a graphical mode, they only have text mode consoles accessible by pressing ctrl alt f1 to f6).

    In short, the problem you are trying to solve does not need to be addressed at the script level; it is the user's problem. If they want to launch it from their graphical explorer, it is up to them to execute it in a terminal or to set up the explorer so that the script is always launched in a terminal (if that is possible).

    Good luck.
    0