Skip to main content
Skip to main content

AG004: Missing Local Variable Declaration

PropertyValue
CodeAG004
SeverityWarning
Sincev0.1.0

Description

An entry in the args=() array references a variable name that has no matching local declaration in the function. argsh's :args parser stores parsed values into local variables, so each field must have a corresponding local <name> declaration.

Example

This triggers AG004:

my_func() {
# missing: local name
local -a args=(
'name|n' "The name to greet"
)
:args "My function" "${@}"
}

How to Fix

Add a local declaration for the variable:

my_func() {
local name
local -a args=(
'name|n' "The name to greet"
)
:args "My function" "${@}"
}

How to Suppress

# argsh disable=AG004
'name|n' "The name to greet"

Or file-wide:

# argsh disable-file=AG004
Was this section helpful?