Bug 464987 - Shell script declared as POSIX-compliant but is not
Summary: Shell script declared as POSIX-compliant but is not
Status: REPORTED
Alias: None
Product: kdevelop
Classification: Applications
Component: general (other bugs)
Version First Reported In: unspecified
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: kdevelop-bugs-null
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-01-29 14:54 UTC by zer0-x.7ty50
Modified: 2023-02-07 19:50 UTC (History)
3 users (show)

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 zer0-x.7ty50 2023-01-29 14:54:45 UTC
The https://invent.kde.org/kdevelop/kdevelop/-/blob/20f2294e0fdfa2c2451a816360a5960887d8cf05/kdevplatform/util/kdevplatform_shell_environment.sh script has the `#!/bin/sh` shebang, so it should be a POSIX-compliant script.
With a test using `checkbashisms` tool I found that it uses a lot of bashisms (features of bash that are not POSIX-compliant):

Please ether use the  `#!/bin/bash` shebang or fix the script to be POSIX-compliant.
Comment 1 Igor Kushnir 2023-01-30 08:48:59 UTC
Which commonly used shell the script does not support?

The last commit that changed that script made it compatible with zsh. Is there a shebang that indicates both bash and zsh are supported?
Comment 2 zer0-x.7ty50 2023-02-01 16:36:00 UTC
(In reply to Igor Kushnir from comment #1)
> Which commonly used shell the script does not support?
> 
> The last commit that changed that script made it compatible with zsh. Is
> there a shebang that indicates both bash and zsh are supported?

For example the Debian Almquist shell (DASH) is a very POSIX-compliant shell, so it doesn't support any additional things like in `zsh` and `bash`.

As I know it is the default shell for `/bin/sh` in both debian and ubuntu:
- https://wiki.ubuntu.com/DashAsBinSh
- https://en.wikipedia.org/wiki/Debian_Almquist_shell#Adoption_in_Debian_and_Ubuntu

 so it will cause problems at least in those two distros. 

The `bash` and `zsh` shells are POSIX-compatible so if the script is made to be POSIX-compliant it should also work in `bash` and `zsh` without problems.

I don't think that there is a shebang for both zsh and bash, but if you don't want to be POSIX-compliant maybe you can create another POSIX-compliant shell script to select between zsh and bash then use the script as the shebang.
Comment 3 Sven Brauch 2023-02-01 17:13:47 UTC
Is this bug report "it doesn't work in Debian and Ubuntu as-is", or is it "my linter says it might not work in Debian and Ubuntu as-is"?
Comment 4 zer0-x.7ty50 2023-02-01 17:44:05 UTC
(In reply to Sven Brauch from comment #3)
> Is this bug report "it doesn't work in Debian and Ubuntu as-is", or is it
> "my linter says it might not work in Debian and Ubuntu as-is"?

It is a report about using `#!/bin/sh` shebang in a non POSIX-compliant script, which should be a bug by it self, since `#!/bin/sh` should be only used in POSIX-compliant scripts.

I did use a linter in my whole /usr/bin directory to check if I can use the `dash` shell as my default shell, and I found this script using things like `if [[ "$1" == "" ]]` rather then `if [ "$1" = "" ]`. I know that this command will not work in the `dash` shell and I tested it, so it's not just a warning from the linter.

I didn't test it in Ubuntu or Debian, but if the `dash` shell is used it will give a `dash: 1: [[: not found` error for this test statement.
Comment 5 Igor Kushnir 2023-02-02 08:35:06 UTC
The script in question kdevplatform_shell_environment.sh is called only by another script kdevelop! in https://invent.kde.org/kdevelop/kdevelop/-/tree/master/app
This other script *is* POSIX-compliant I think, and it executes kdevplatform_shell_environment.sh either in zsh or in bash. So I expect the wrong shebang in kdevplatform_shell_environment.sh won't cause problems to KDevelop users. On the other hand, reverting it to `#!/bin/bash` should also be fine, I think. Or would it somehow work worse for zsh users?
Comment 6 Eugene Shalygin 2023-02-07 19:50:24 UTC
(In reply to Igor Kushnir from comment #5)
> Or would it somehow work worse for zsh users?

No, it should not be a problem for zsh users.