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

SC2320 warning in function #2990

Open
4 tasks
BrentHuang opened this issue May 28, 2024 · 0 comments
Open
4 tasks

SC2320 warning in function #2990

BrentHuang opened this issue May 28, 2024 · 0 comments

Comments

@BrentHuang
Copy link

For bugs

For new checks and feature suggestions

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

#!/usr/bin/env bash

demo() {
    echo "in function demo..."
    echo "the script name: $0"
    echo "argument count (not include the script itself): $#"
    echo "the first argument: $1"
    echo "the second argument: $2"
    echo "the 10th argument: ${10}"

    # shellcheck disable=SC2145
    echo "argument list: $@"  # echo 输出字符串,这里 shellcheck 会告警,字符串形式用 $* 就不会告警
    echo "argument list string: $*"
    echo "process id: $$"

    ret=$?
    echo "command exited with ${ret}"
    if [[ ${ret} -ne 0 ]]; then
        echo "failed"
    fi
}

demo 1 2 3

Here's what shellcheck currently says:

In ./docs/test.sh line 16:
ret=$?
^-- SC2320 (warning): This $? refers to echo/printf, not a previous command. Assign to variable to avoid it being overwritten.

Here's what I wanted or expected to see:

no SC2320 warning.

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