Bug 431233 - Fails to execute .sh shell script file that lacks a shebang
Summary: Fails to execute .sh shell script file that lacks a shebang
Status: REOPENED
Alias: None
Product: frameworks-kio
Classification: Frameworks and Libraries
Component: general (show other bugs)
Version: 5.77.0
Platform: Debian testing Linux
: NOR normal
Target Milestone: ---
Assignee: KIO Bugs
URL:
Keywords:
: 431244 (view as bug list)
Depends on:
Blocks:
 
Reported: 2021-01-06 17:22 UTC by David
Modified: 2021-05-12 22:57 UTC (History)
6 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description David 2021-01-06 17:22:43 UTC
SUMMARY
If try to execute a .sh script with dolphin, it will try to execute it as a binary, failing to do anything.

STEPS TO REPRODUCE
1. Create a .sh text file that would do something simple, such as `touch deleteme`.
2. Set the file as executable.
3. Click (or double click) said file in dolphin and choose to execute it.

OBSERVED RESULT
Fails to execute it, tries to execute as if it were a binary file.

EXPECTED RESULT
Should execute the shell script.

SOFTWARE/OS VERSIONS
Windows: 
macOS: 
Linux/KDE Plasma: 
(available in About System)
KDE Plasma Version: 5.20.4
KDE Frameworks Version: 5.77.0
Qt Version: 5.15.2

ADDITIONAL INFORMATION
Comment 1 Christoph Feck 2021-01-06 17:25:39 UTC
Does it start with the shebang?
Comment 2 David 2021-01-06 17:28:41 UTC
(In reply to Christoph Feck from comment #1)
> Does it start with the shebang?

It does work when I add it. Although I'd also expect it to use the defaults if it's missing it, provided it's a .sh file.
Comment 3 Christoph Feck 2021-01-07 14:41:07 UTC
*** Bug 431244 has been marked as a duplicate of this bug. ***
Comment 4 Nate Graham 2021-01-07 17:05:14 UTC
I suppose KIO could detect this from the file extension.
Comment 5 Ahmad Samir 2021-04-21 11:48:40 UTC
I think this is not a bug, you should add a proper shebang to a shell script.
Comment 6 David 2021-04-21 16:30:57 UTC
(In reply to Ahmad Samir from comment #5)
> I think this is not a bug, you should add a proper shebang to a shell script.

Running 'sh file.sh' does not require a shebang. Neither does the software which gets the mimetypes.
Comment 7 Nate Graham 2021-04-21 16:40:42 UTC
It may not technically require it, but it's good practice, precisely to avoid these kinds of issues. Just add the shebang. :)
Comment 8 Ahmad Samir 2021-04-22 00:32:48 UTC
(In reply to David from comment #6)
> Running 'sh file.sh' does not require a shebang. 
[...]
You run `sh file.sh` from terminal, using a shell, bash, zsh...etc; but KProcess/QProcess doesn't know that, and without that info the system call it'll use fails, IIUC.
Comment 9 David 2021-04-23 12:36:27 UTC
(In reply to Ahmad Samir from comment #8)
> (In reply to David from comment #6)
> > Running 'sh file.sh' does not require a shebang. 
> [...]
> You run `sh file.sh` from terminal, using a shell, bash, zsh...etc; but
> KProcess/QProcess doesn't know that, and without that info the system call
> it'll use fails, IIUC.

It'd then be helpful to at least show a message to the user that it needs a shebang, instead of tying to execute it as a binary. I assume it already has the mimetype information when it attemps to run it.
Comment 10 Ahmad Samir 2021-05-12 22:57:04 UTC
That's a good point, reopening (I don't know how feasible it is to actually detect the lack of shebang beforehand, but it's worth investigating).