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

Repeat-only for loop without SC2034 #1134

Closed
szepeviktor opened this issue Mar 3, 2018 · 4 comments
Closed

Repeat-only for loop without SC2034 #1134

szepeviktor opened this issue Mar 3, 2018 · 4 comments

Comments

@szepeviktor
Copy link

I'd like to repeat something N times:
for UNUSED in {1..16}; do echo 1; done

but shellcheck tells me ^-- SC2034: UNUSED appears unused. Verify it or export it.

What could I do?

@szepeviktor
Copy link
Author

I know-I know: # shellcheck disable=SC2034

@koalaman
Copy link
Owner

koalaman commented Mar 3, 2018

You can also use the name _. This is a feature in JS Python, Haskell and others, and semi-commonly used in sh in e.g. read foo _ bar

@koalaman koalaman closed this as completed Mar 3, 2018
@szepeviktor
Copy link
Author

szepeviktor commented Mar 3, 2018

Thank you for your continued support.

@davisRoman
Copy link

This was useful. Thank you!

fishilico added a commit to fishilico/home-files that referenced this issue Apr 14, 2024
shellcheck 0.10.0 reports:

    In bin/systemd-analyze-plot line 32:
        read -r 2> /dev/null
        ^--^ SC3061 (warning): In POSIX sh, read without a variable is undefined.

Silence this by using an unused variable.
koalaman/shellcheck#1134 suggests using `$_`
for such a use-case.
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

3 participants