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

Add new rule - Don't use process substitution to avoid masking return values #3094

Open
2 tasks done
ggjulio opened this issue Dec 3, 2024 · 3 comments
Open
2 tasks done

Comments

@ggjulio
Copy link

ggjulio commented Dec 3, 2024

For new checks and feature suggestions

Here's a snippet or screenshot that shows the problem:

set -euo pipefail
readarray -t my_array < <(some_command_failing | sort -u)
echo passed

Here's what shellcheck currently says:

No errors

Here's what I wanted or expected to see:

Process substitution should be usually avoided to avoid masking return values at least when errexit is used.

It's a similar issue than when using a subshell in a variable declaration:

Declare and assign separately to avoid masking return values. (shellcheck SC2155)

IMHO it would make sense to create a new rule :

Don't use process substitution to avoid masking return values. (shellcheck SCxxxx)

image
image

source: http://mywiki.wooledge.org/BashFAQ/105

Bad example:

readarray -t my_array < <(some_command | sort -u)

Good example:

output=$(some_command | sort -u)
readarray -t my_array <<< "${output}"

Originally posted by @ggjulio in #3084 (comment)

@ggjulio ggjulio changed the title New rule New rule - Don't use process substitution to avoid masking return values Dec 3, 2024
@ggjulio ggjulio changed the title New rule - Don't use process substitution to avoid masking return values Add new rule - Don't use process substitution to avoid masking return values Dec 3, 2024
@wileyhy
Copy link

wileyhy commented Dec 7, 2024 via email

@ggjulio
Copy link
Author

ggjulio commented Dec 7, 2024

@wileyhy This an opinion that not everyone share. I cited a source that is against errexit as example but it's not the topic of this issue.

Some shellcheck rules are enabled/disabled based on whether errexit is on/off, so there is no point of debating about it.

To balance the original source cited :

Please don't flood this issue with a second response. Either open a different issue, or use GH discussion / Reddit.

@wileyhy
Copy link

wileyhy commented Dec 9, 2024 via email

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