Function references arguments but no caller passes any
SC2120 flags a function that reads `$1`/positional params when every call site invokes it with zero arguments.
Problem
ShellCheck performs a whole-script analysis and notices when a function's body reads positional parameters (`$1`, `$2`, `"$@"`, etc.) but every call to that function in the file passes no arguments at all. In that case the parameters the function reads are not the ones you probably intended — they leak in from the caller's own context — making the parameter references dead or misleading code. This is the mirror image of SC2119: SC2119 flags the call site (calling without args), SC2120 flags the function definition (expecting args nobody supplies).
Bad
log_message() {
echo "[LOG] $1"
}
log_message # called with no args anywhere in the scriptGood
log_message() {
local msg="$1"
echo "[LOG] $msg"
}
log_message "starting up"Explanation
Fix this by either passing the expected arguments at every call site, or, if the function is genuinely meant to take no input, removing the positional-parameter references and using a fixed value or an explicitly named variable instead. Consistently calling functions with the arguments they read makes data flow visible to both readers and static analysis.
Related
SC2119
SC2034
SC2124
When It Matters
The function reads $1, but no caller anywhere in the file supplies it. That is either dead parameter handling left behind by a refactor, or a call site that lost its argument — and in the second case the function silently operates on an empty value. It is a useful signal in long scripts where a helper gained a parameter and one of its five call sites was missed.
Second Example
Note
A default makes the zero-argument call correct by construction, rather than accidentally harmless.
Exceptions
A function that is part of a library sourced by other scripts has callers ShellCheck cannot see. Add "# shellcheck disable=SC2120" above the definition with a comment saying the function is part of the public interface of the file.
Faq
Q
How do I mark a parameter as optional?
A
Assign it with a default: local flag=${1:-}. That documents the optionality and silences the warning.
Q
Does the warning appear for exported functions?
A
ShellCheck only sees one file at a time, so any function called from elsewhere may be flagged. Disable it at the definition with a note.
Q
Is $# useful here?
A
Yes — branching on the argument count, if [ $# -eq 0 ], makes the two modes of the function explicit.