Ubuntu – An example of a generic shell script that will run correctly in the terminal but not when double-clicked

bashcommand linedash-shellscripts

I'd really like to understand the underlying reasons why some scripts work from the command line but not when double-clicked.

Is there an example of a script that does something simple, like echoing a variable or something like that, which would reproducibly work in the command line, but then fail to work when double-clicked?

To be clear, I mean it should run in both instances, but when double-clicked it should fail to perform its task correctly, and it should do this on any recent Ubuntu installation. I'm hoping that by being able to reproduce the behaviour I can understand it and fix it myself in the future.

Best Answer

  • Easiest example:

    • create a file "test" and put

      echo "Hello World!"

      in it

    • make it executable with chmod 700 test
    • do ./test on commandline and it will output

      Hello world!

    From Nautilus:

    • default: doubleclick and it will open as a text file
    • when set to "run text files" from Nautilus preferences it will flicker a couple of times and then does nothing.

    But this is intended behaviour. For Nautilus you would need to create a script that does a "pop up" with the text "Hello world!" in it.


    import os
    os.system('zenity --info --text="Hello world!!"')

    would show ...

    enter image description here

    By the way: this also works from command line when you have a desktop. On a tty it would show an error "Failed to connect to Mir".

    and fix it myself in the future

    I doubt though there is something to fix. Executing in command line and executing in Nautilus are 2 different things.

  • Related Question