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

Verification of the script preamble? #54

Open
jstasiak opened this issue Jan 23, 2023 · 1 comment
Open

Verification of the script preamble? #54

jstasiak opened this issue Jan 23, 2023 · 1 comment

Comments

@jstasiak
Copy link

Hey! First of all thank you for this project, it's really helpful and I'm going to integrate it into our CI pipeline(s).

What I'm thinking about is I'd also like to verify that our bash scripts have

shopt -s nullglob globstar

and

if test "$BASH" = "" || "$BASH" -uc "a=();true \"\${a[@]}\"" 2>/dev/null; then
    # Bash 4.4, Zsh
    set -euo pipefail
else
    # Bash 4.3 and older chokes on empty arrays with set -u.
    set -eo pipefail
fi

at the beginning. Do you think there's place for this in shellharden (behind a flag, presumably)? I could open a PR if so.

@anordal
Copy link
Owner

anordal commented Mar 7, 2023

Depending on details, it's not a good fit for how Shellharden works now, but might be worth doing.

If there is to be much value in doing it in Shellharden, instead of scripting something quickly,
the operation should be idempotent enough to recognise and accept other flavors of these flags
(though these are good defaults).
These flags only need to be set before they are used, but that can be anywhere.
So we need to read the whole file before deciding what's missing at the start.

Shellharden works as a filter: You can pipe an endless stream into it and watch its output live.
The parsed syntax tree is only iterated, not recorded. So no decisions about past output.
It would have to do two passes (and no longer be a filter) in order to do that.

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

No branches or pull requests

2 participants