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
Consistently use `#! /usr/bin/env bash' as shebang #2308
Conversation
This increase portability of semgrep on platforms not having bash as /bin/bash.
Even though most of our projects are open-source, we ask contributors to sign a contributor license agreement before we merge your PR. There are a few reasons for this that we've learned over time: it's important to have an explicit statement that you wrote the code yourself, that no one else has a copyright claim on it, and it gives us as the long-term maintainers flexibility should we need to change the license in the future (though we don't plan to). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this looks great @iamleot -- thanks for the contribution! @cla-bot check
tagging @DrewDennison or @brendongo for packaging/devops review
@mjambon or @minusworld -- could we write a semgrep generic-mode rule for #!/bin/bash -> #! /usr/bin/env bash?
My attempt: https://semgrep.dev/s/vzxn
Thanks @ievans! |
@cla-bot check pls (seems flaky) |
The cla-bot has been summoned, and re-checked this pull request! |
Really a minor cosmetic nit: in my experience it is more common to have In pkgsrc package system we have the following sed(1) invocation to spot shebangs (via pkgsrc/mk/check/check-interpreter.mk:67): sed -n -e '1s/^#![[:space:]]*\([^[:space:]]*\).*/\1/p' -e '1q' (...and then the interpreter in While checking possible
(both unquoted and quoted via a single quote ( Anyway, these are mostly my side-notes on thinking aloud about the rule proposed by @ievans! :) (i.e. not strictly related to this PR :)) |
Of course I have not skimmed enough! ( |
However, despite the bit pessimistic TODO, I was available to build it on NetBSD/amd64 -current and pkgsrc-current after installing devel/ocaml-opam (and wip/mccs), hacking a bit ocaml-tree-sitter to avoid a `sudo make install` and with the following PR: semgrep/semgrep#2308 ...and keeping semgrep-core and spacecat binaries available in PATH environment variable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, this is good practice. We should probably write a semgrep rule for it, too! Thanks for the patch.
Edit: oh, I clicked directly to the review screen and failed to notice the discussion above. I see I'm not the only one with these thoughts :D
This one works only with the standard no-space rule, but adds a rule ID, message, and matching any binary, not just |
This increase portability of semgrep on platforms not having bash as
/bin/bash.
This is not just a possible theoretical problem but actually helps helping build
semgrep on NetBSD!
(And, FTR, I was finally able to build semgrep and can use it on NetBSD with mostly just this patch and a couple of notes that I should tidy up and share (but probably only relevant for NetBSD and pkgsrc users! :))