Can't run shell scripts with double click

Forgive me if this is in the wrong place.

My problem is rather simple. Before switching to openSUSE I used to use linux mint. On there I could write a script, make it executable then when I double-clicked on it a terminal window would open showing me my script running. The script isn’t even a script as much as it is just a convenience, I’m simply trying to create and ‘update’ script that I can double click instead of opening up a terminal then starting to type or using yast etc.

Here’s the code:


#!/bin/bash
sudo zypper patch
sudo zypper up
fortune

At first when I double clicked on it, it would complain about having no suitable application about opening a shell script, so I added konsole to the top of the preferred apps list in the file’s properties and made sure I hadn’t just made a typo when making it executable so I ran ‘chmod +x file’ again.

Now however, it doesn’t do anything. It doesn’t open but there’s no error either. I thought it may be running in the background but


ps aux | grep Update

(Update is the file name of the script)
and


ps aux | grep zypper

Both only show the one line of output that we all know is just the process that I just ran with ps aux. So, how do I get a bash/sh script to run in a visible terminal window when I double click on it? I fear this may be painfully simple to the point where I’ll be embarrassed about asking but I can’t think of anything else :frowning:

All help is appreciated.

Hi, try with /bin/sh instead of /bin/bash. HTH Lenwolf

I already tried that. Same result.

And where do you “double click on it”? In a file manager? Which one? The file manager (or desktop environment) has to run it in a terminal window in that case. How you set that up would depend at least on which DE you use.

On my desktop.

I’m running kde 4.14.6. The file manager I use is dolphin.

It’s very strange that extra legwork is required for this considering on other distros (or probably more accurately put: in other desktop environments) you can simply make a file with a script in and run it with a double-click.

i.am.not.an.rmfr.script.you.just.received.from.your.friend.as.a.joke.sh <double click> Aww, ****.

Maybe try:

#!/bin/bash
sudo konsole -e --noclose zypper patch && sudo zypper up && fortune


Under Dolphin, change the program to execute from konsole to sh.

I did this ALONG time ago, never been extremely good at the console, always just fly by the seat of my pants.
But if I remember correctly, this should work, maybe.

By the way, if this worked, please click on the star below my post, I am a little past the newbie stage and could use the up!

Dangit! mistype:

#!/bin/bash
konsole -e --noclose sudo zypper patch && sudo zypper up && fortune

There, corrected.

Well, as you corrected yourself, this has absolutely nothing to do with the distribution, but only with the desktop environment.
On Mint you probably didn’t use KDE. You could do the same in openSUSE, there’s GNOME, XFCE, LXDE, E17, LXQT, MATE, … available.
You could even just use a different file manager in KDE, that would run your script in a terminal window automatically.

One way to set this up in KDE would be to create a “link” (a .desktop file actually) via right-click->New->Link to Application…, set your script as command to run on the “Application” tab, and enable “Run in terminal” in the “Advanced Options” there.

But depending on what you actually want to do in that script, there might be better ways to do it than with a script on your desktop.

Btw, there’s no need to run “zypper patch” if you run “zypper up” immediately afterwards… :wink:

Seems like you’re trying to make the point that not being able to run a script with a double-click is a security feature. Thing is nobody in their right mind would run a script someone else sent to them without first reading it and even if they were, the fact you can’t run it with a double click wouldn’t stop them running it some other way ie from terminal.

@almcneill

#!/bin/bash
konsole -e --noclose sudo zypper patch && sudo zypper up && fortune

This ^ causes a konsole window to flash open but it immediately closes again after.

I forgot to mention:
Does it really have to be a double-click?

Try to right-click on your script, and choose Actions->Run in Konsole… :wink:

Yeah, right.
That’s the reason why there exist absolutely no Windows systems that are infected by a virus… :sarcastic:

I believe patch, unlike up, also installs security patches.

Running zypper up as well afterwards is indeed pointless but it’s just an obsessive habit of mine, I also check yast > online updates afterwards as well even though that does the exact same thing. For some reason I get very obsessive about updating linux systems.

It’s like trying to open your door straight after you locked it to makes sure its locked even though the key went all the way around and you heard the click.

With apps that are compiled and the user cannot view the code that is being run beforehand, unlike with scripts. I’m sure there’s no windows user out there being infected by a batch file unless they’re a total novice.

Regardless, I’ve gone with your suggestion to use a link to my script. Thank you for helping.

Although if anyone knows how to rewrite my script in a way to make linking to the script unnecessary I’d be grateful.

No, not unlike up.
zypper up installs “security patches” (which are just updates like any others) too.

Running zypper up as well afterwards is indeed pointless

Running “zypper up” afterwards is not pointless as it installs all other updates that “zypper patch” does not install.
But it makes “zypper patch” pointless.

but it’s just an obsessive habit of mine, I also check yast > online updates afterwards as well even though that does the exact same thing. For some reason I get very obsessive about updating linux systems.

Well, one could say you have a problem then… rotfl!

It’s like trying to open your door straight after you locked it to makes sure its locked even though the key went all the way around and you heard the click.

Not really.

If you say so…

PS: To your original question, you could also go into “Configure Desktop”->File Associations, and specify to open shell scripts with “konsole --hold -e %f” as preferred application. That’s what Actions->Run in Konsole does.

You already got a suggestion from almcneill.

And I told you three ways how to run any script from the desktop or dolphin without rewriting it.
The file association change in my last post is probably exactly what you want to achieve.

How very rude.

Firstly, the output from zypper patch says it is about to install security patches (when they’re available) as well as available package updates. Zypper up only says its about to install the package updates, not the security patches.

>One could say you have a problem then
>Not really

It was a comparison because I knew it sounded strange, I really don’t appreciate your tone. There’s no need to be bitter and try insult me simply because you know something I don’t and quite frankly if that’s how moderators act I may have made a mistake in joining this forum.

Trying to poke fun at a newcomer that’s asking for help is not funny or clever. I’m sure you have quirks and habits that we could make fun of too, but we’re nice people.

his suggestion didn’t work as I said in my earlier post.

I know you did, that’s why I told you which one I had gone with and said thank you for helping. Please stop going out of your way to be a dick.

I think you’re trying to find an insult where none exists.