Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use POSIX syntax for Bash detection #127

Merged
merged 1 commit into from
Apr 21, 2022
Merged

Conversation

gaelicWizard
Copy link
Contributor

@gaelicWizard gaelicWizard commented Jan 27, 2022

Don't depend on running modern Bash/ksh/zsh when we're trying to detect if we're running a modern bash.

@dimo414
Copy link
Collaborator

dimo414 commented Jan 28, 2022

Is there a particular shell / version where the existing code doesn't work?

@gaelicWizard
Copy link
Contributor Author

Most major linux distributions ship /bin/sh as Dash, which is explicitly POSIX-compatible and nothing else.

@dimo414
Copy link
Collaborator

dimo414 commented Jan 29, 2022

Ok, if the goal is to support Dash it'd be good to add test coverage of that. Can't hurt to add a comment here as well, noting the syntax is intentional to support Dash. I'm still not certain there's a need to support Dash, but it doesn't hurt.

@gaelicWizard
Copy link
Contributor Author

It's not really about dash specifically, but rather about the assumption that /bin/sh is bash. I'm sure there's more than a few places that assumption still survives. Dash is just a good example because it made waves when Debian switched /bin/sh; there's pages and pages of discussion in mailing list archives about it.

@dimo414
Copy link
Collaborator

dimo414 commented Jan 29, 2022

the assumption that /bin/sh is bash.

I don't mean to come across as thick, but where exactly is that assumption being made? The installation instructions (not to mention the project's name) are clearly specific to bash, and I don't see any reference in this repo to /bin/sh. I don't understand how someone could end up sourcing bash-preexec.sh in a dash shell short of misconfiguring their rc files.

@gaelicWizard
Copy link
Contributor Author

I don't disagree, but then why check at all?

@dimo414
Copy link
Collaborator

dimo414 commented Jan 30, 2022

IMO it would be reasonable to not have this check and put the burden on the user to ensure their shell(s) are configured correctly, but it's probably not practical to remove at this point. Notably, #113 reported Zsh users accidentally sourcing bash-preexec (I imagine because they chose to source ~/.bashrc from their ~/.zshrc or similar, which is probably not a good idea but people do it anyways). For reference, the check was added back in bbec4c7 seemingly just out of an abundance of caution.

So just to be clear, you're not actually running into a situation where you expect to source bash-preexec in a Dash shell, right?

@gaelicWizard
Copy link
Contributor Author

Correct 👍

@dimo414
Copy link
Collaborator

dimo414 commented Jan 31, 2022

In that case I'm -1 on this change simply because it's not needed. But if you feel strongly this line should be dash-compatible it would be appropriate to include test coverage to enforce this support going forward.

But in that vein it's also worth considering what would happen if bash-preexec ever utilized some bash syntax that dash couldn't even parse (causing it to fail before even reaching this line). IMO it would be wrong to avoid that syntax just because it breaks dash, since the library isn't intended to work with dash in the first place. Which suggests to me that we shouldn't bother with dash compatibility at all.

@gaelicWizard
Copy link
Contributor Author

That's fair.

Since it's a shellscript, it would exit before reaching anything past those top lines, which I understand to be the point of moving those lines to the top of the file. It won't even parse the whole script at all; it's not compiled 😉

@dimo414
Copy link
Collaborator

dimo414 commented Feb 1, 2022

My point is simply that if such a situation arose I don't think it'd be worth reverting the (presumably desirable) bashism in order to satisfy dash.

@akinomyoga
Copy link
Contributor

I don't think the current check in the master, which requires Bash to check if it is Bash, makes any sense. I think we should merge this PR or otherwise completely remove the check for Bash. In my opinion, even if it is not consistent with the later codes which use full Bash features, it is better to check the current shell using the POSIX feature. There are always beginner users doing something strange that we cannot predict.

@dimo414
Copy link
Collaborator

dimo414 commented Apr 21, 2022

I for one don't mind removing the check, but if people feel strongly that the check needs to be dash-compatible there should be test coverage of that behavior.

@akinomyoga
Copy link
Contributor

Thanks for your prompt reply! Then, I feel we can add tests and merge it. [ This is a side note but the check is not only affected by ash family (dash/ash/busybox sh) but also by other (non-ksh-like) POSIX shells including /bin/sh of each BSDs, Solaris, etc. ]

@rcaloras
Copy link
Owner

Late arrival to this thread! FWIW, this check was originally POSIX compatible and was changed without much consideration to use [[ as part of this PR https://github.com/rcaloras/bash-preexec/pull/7/files.

@rcaloras
Copy link
Owner

Appreciate the PR and everyone's input. I agree with @dimo414's take. However, in this situation I'm supportive if other contributors are interested in merging. I don't think there's any harm and would rather be pragmatic than turn into a larger debate.

@rcaloras rcaloras merged commit d308800 into rcaloras:master Apr 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants