LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Basic question on bash scripts (https://www.linuxquestions.org/questions/linux-newbie-8/basic-question-on-bash-scripts-4175652056/)

Drosera_capensis 04-13-2019 01:28 AM

Basic question on bash scripts
 
1 Attachment(s)
Hello everyone.

Ubuntu BionicBeaver 18.04 on my side.

When double-clicking on a bash script in the Nautilus graphical interface, a window appear (see picture attached).

However, executing the bash script on the shell with this command is working and the program is opening.
Quote:

sh file
Why is it the case? Why is it not possible to execute a bash script just double-clicking at it?

Thanks for your help, cheers.

wpeckham 04-13-2019 07:19 AM

This may have more to do with Nautilus than with shell scripting.
Disclaimer: I am not currently using Nautilus, and therefore cannot easily test behavior.


I would research Nautilus behavior first. Also try to right click on your script icon and examine what nautilus THINKS it has as properties. This may be instructive.

That said:
First: make sure that your shell script is written so that it does not depend upon the PATH or other environmental variables. You cannot be certain that the environment it runs with under a GUI is the same as that in your normal terminal session.

Second: write your script so that it does something to log that it ran, or that a window opens for it to display that you have time to SEE it.
You need to be SURE what is happening, and evidence to support your ideas about what is going on. A bit of logging may help.

Third: permissions on the script should be such that it is executable. Do not depend upon Nautilus to be able to read your mind and add sh or bash to the desktop link magically, it must run when called by name alone. (Or full path and name.)

Drosera_capensis 04-13-2019 08:38 AM

Hello wpeckham, thanks for your answer.

It seems that I was using Nautilus as you quote in the first line of your answer.

Testing another software called Nemo (!) provides the option of running bash scripts directly as I*was intending to do.

Nevertheless, I*have noted your subsequent advises and will keep them in mind for further inquiries.

Cheers!


All times are GMT -5. The time now is 08:46 PM.