Bug 476083 - External Tools / Run Shell Script : does not work
Summary: External Tools / Run Shell Script : does not work
Status: RESOLVED FIXED
Alias: None
Product: kate
Classification: Applications
Component: general (show other bugs)
Version: unspecified
Platform: Flatpak Linux
: NOR minor
Target Milestone: ---
Assignee: KWrite Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-10-25 13:55 UTC by remi
Modified: 2023-10-25 19:53 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description remi 2023-10-25 13:55:53 UTC
SUMMARY
External Tools / Run Shell Script : does not execute the shell script

Example script :
    #!/bin/bash
    echo hello
    echo hello > ~/hello

STEPS TO REPRODUCE
1. Open a valid bash script :
- begins with #!/bin/bash
- owned by the current user
- has +x file permission
- executed successfully when launched from konsole
2. Click Menu > Tools > External Tools > Tools > Run Shell Script

OBSERVED RESULT
Konsole window opens and closes immediately
The script is not executed

EXPECTED RESULT
The script is executed
Konsole window shows the result
Konsole window waits a key press to close the window

SOFTWARE/OS VERSIONS
Linux: Debian 11
KDE Plasma Version: 
KDE Frameworks Version: 
Qt Version: 

ADDITIONAL INFORMATION
This bug is due to the default command arguments configured with "Run Shell Script" tool, which is :
    -e sh -c "cd %{Document:Path} && pwd && chmod -vc a+x %{Document:FileName} && ./%{Document:FileName} ; echo Press any key to continue. && read -n 1"

When running the following command :
    sh -c read -n 1

We get an error :
    -n: 1: read: arg count

On my system it can be solved by replacing :
    echo Press any key to continue. && read -n 1"
by :
    echo Press enter to continue. && read null"

Which is a valid sh command

I can open a minimal merge request but I don't know the eventual implications on other systems
Comment 1 remi 2023-10-25 13:58:42 UTC
Some additional questions :

Is it reasonable to change the file permission (the 'chmod' part) by default ?

What's the goal of 'pwd' in the command ?
Comment 2 remi 2023-10-25 14:01:07 UTC
The default command has been introduced in this commit :
https://invent.kde.org/utilities/kate/-/commit/0d1c47d198f6a3220fb10973635689416feab4e9
Comment 3 remi 2023-10-25 14:03:14 UTC
Reply to my previous comment : 'pwd' is useful, otherwise the konsole window does not show the path
Comment 4 Bug Janitor Service 2023-10-25 17:40:30 UTC
A possibly relevant merge request was started @ https://invent.kde.org/utilities/kate/-/merge_requests/1330
Comment 5 Christoph Cullmann 2023-10-25 19:53:02 UTC
Git commit 33ca1767dde9bec02e2f0fc49d6b617a855cfc42 by Christoph Cullmann, on behalf of Rémi Peuchot.
Committed on 25/10/2023 at 21:52.
Pushed by cullmann into branch 'master'.

Fix run_shell_script default command arguments

run_shell_script default command argument contains an invalid 'sh'
command :
  read -n 1

Which returns the following error :
  -n: 1: read: arg count

The 'sh' read command syntax seems to be :
  read my_variable
letting the user to enter a value and press enter,
so we can use $my_variable later.

This fix consists of replacing the read command by a valid one :
  read null

Which let the konsole window opened until the user press enter.

M  +1    -1    addons/externaltools/externaltools-config/run_shell_script

https://invent.kde.org/utilities/kate/-/commit/33ca1767dde9bec02e2f0fc49d6b617a855cfc42