Skip to content

Fixing some style issues in shell scripts with shellcheck #77290

Closed

Description

@tesuji

There are some style issues in shell scripts in this repository.
ShellCheck is an useful tool to find bugs in shell scripts.
One could run git ls-files '*.sh' to find all shell script files and pipe the result to xargs shellcheck.
Or just fix it file-by-file.

Note that this issue doesn't talk about including shellcheck tests in CI.

@rustbot modify labels: E-easy E-mentor T-infra

Activity

  1. added
    E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
    E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.
    T-infraRelevant to the infrastructure team, which will review and decide on the PR/issue.
    on Sep 28, 2020
  2. pta2002 commented on Sep 28, 2020

    @pta2002

    Can I have a go at this? I think I can work on it.

  3. tesuji commented on Sep 28, 2020

    @tesuji
    ContributorAuthor

    Sure. But it's known that there are some false-positive suggestions in shellcheck.
    Most of them should be caught by CI (by falling to execute).

  4. pta2002 commented on Sep 28, 2020

    @pta2002

    Alright, I'll have a look at what fails CI then!

  5. added
    C-cleanupCategory: PRs that clean code up or issues documenting cleanup.
    on Sep 28, 2020
  6. pta2002 commented on Sep 28, 2020

    @pta2002

    Just a question, I've reached src/ci/docker/scripts/android-start-emulator.sh, which starts with a shebang referencing #!/bin/sh instead of the usual #!/usr/bin/env bash, and then goes on to use &>, which shellcheck warns is not a thing on POSIX sh. Should this be changed to bash or is there a reason for this?

  7. pta2002 commented on Sep 28, 2020

    @pta2002

    Also, what should I do about the unused variables that pop up here and there? Some like TARGET seem like they might be nice keeping if not just for making the file follow the same structure as the others, but since they're unused I'm not sure if I should delete them.

  8. tesuji commented on Sep 29, 2020

    @tesuji
    ContributorAuthor

    then goes on to use &>, which shellcheck warns is not a thing on POSIX sh

    Just use 2>&1 instead. I don't know if android has bash, so let's keep it sh.

    unused variables that pop up here and there

    You could grep for the unused variables in src/ci.
    Most of them should be passed via environment variables.
    You could ignore unused var warnings.

  9. pta2002 commented on Sep 29, 2020

    @pta2002

    So if they're unused they should probably be exported then, no? The ones shellcheck is warning about aren't

  10. tesuji commented on Sep 29, 2020

    @tesuji
    ContributorAuthor

    You could remove it. File a draft PR to see if it run successfully.

  11. sasurau4 commented on Nov 2, 2020

    @sasurau4
    Contributor

    The previous PR seems abondoned, I'll try it.

  12. jyn514 commented on Nov 2, 2020

    @jyn514
    Member

    The previous PR seems abondoned, I'll try it.

    @sasurau4 the PR wasn't abandoned, it was rejected because it wasn't clear the improvements were worth the potential breakage. I see in #78666 you only fixed warnings shellcheck marked as 'error's, that might have a better chance.

  13. added a commit that references this issue on Nov 6, 2020
  14. added a commit that references this issue on Nov 27, 2020
  15. sjakobi commented on Mar 26, 2021

    @sjakobi
    Contributor

    Is there still work to do here now that #78666 has been merged?

  16. JohnTitor commented on Mar 31, 2021

    @JohnTitor
    Member

    Triage: #78666 fixed the shellcheck errors and I don't think it's much worth applying shellcheck's suggestions to our source, while fighting a lot of regressions, so I'm going to close the issue. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-cleanupCategory: PRs that clean code up or issues documenting cleanup.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.T-infraRelevant to the infrastructure team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions