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

opening a pipe to a while read loop flags assignment of $? as SC2319 #3165

Open
solstice333 opened this issue Mar 21, 2025 · 0 comments
Open

Comments

@solstice333
Copy link

Min repro:

#!/usr/bin/env bash

while read line; do
    rev=$line

    [[ "${rev#foo}" == "$rev" ]]
    is_foo=$?   # This $? refers to a condition, not a command. Assign to a variable to avoid it being overwritten. See SC2319.

    echo "$rev: $is_foo"
done < $TEMP/foo.lst | sort

where is_foo=$? is flagged with SC2319. The expectation is for this line not to be flagged bc $? is being assigned.

Removing the pipe of while read ... to sort causes the SC2319 warning to disappear:

#!/usr/bin/env bash

while read line; do
    rev=$line

    [[ "${rev#foo}" == "$rev" ]]
    is_foo=$?

    echo "$rev: $is_foo"
done < $TEMP/foo.lst
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

1 participant