mathieugood
Posts: 3
Joined: Sun Oct 07, 2012 2:42 pm

How to double click a .sh file and execute in the Terminal

Sun Oct 07, 2012 2:45 pm

I want to make a .sh file run via the Raspbian GUI run by simply double clicking on it.

I already made the file executable via chmod +x run in the Terminal by simply double clicking on it.

Right now, it opens a dialog pop-up telling me :

"This text file 'myfile.sh' seems to be an executable script. What do you want to do with it?"

Execute, Execute in Terminal, Open, Cancel

Clicking on any of the first two choices is without any effect. It just closes the dialog window.

Otherwise I can just run the script fine in the Terminal, just by typing ./myfile.sh

Any idea what else I should do ?

elatllat
Posts: 1337
Joined: Sat Dec 17, 2011 5:05 pm

Re: How to double click a .sh file and execute in the Termin

Sun Oct 07, 2012 3:05 pm

How are you testing "without any effect"? (echo "starting script">>/log.txt)
What's in your script? (#!/bin/bash)
There is some place you can tell the GUI to just run it without asking but for safety I normally only apply that to a made up extension .shx
SBC with 32GB RAM: https://hardkernel.com

FAQ : https://raspberrypi.stackexchange.com

Unanswered: https://www.raspberrypi.org/forums/search.php?search_id=unanswered

mathieugood
Posts: 3
Joined: Sun Oct 07, 2012 2:42 pm

Re: How to double click a .sh file and execute in the Termin

Sun Oct 07, 2012 3:38 pm

I added echo "starting script">>/log.txt at the beginning of the script, after #!/bin/bash which I already had. When double clicking and choosing either Execute or Execute in Terminal, it does nothing, and doesn't create the log.txt file.

The script won't start I believe.

Which is weird, I tested in in on my mac (by changing the extension from .sh to .command) and it works perfectly. I also tried changing to .command, with the same result.

I need to make a terminal window appear and run a script, waiting for user input.

Here is the beginning of the script (without the log thing).

Code: Select all

#!/bin/bash
# Get the OS name to know which app to execute
osname=`uname -s`
# Goes to user's home directory
echo `cd`
echo `clear`
# Nice stuff
echo "---------Watch-O-Tron 2000 v4.2---------------"
echo " "
# Prompts the user with URL
echo "Would you kindly copy the URL of the video you want to watch?"
read URL
# Parses the URL to get the filename
filename=${URL##*/}
echo "------------------------------------------------------"

Return to “Beginners”