Skip to content

Latest commit

 

History

History
28 lines (18 loc) · 570 Bytes

SC2168.md

File metadata and controls

28 lines (18 loc) · 570 Bytes

Pattern: Use of local for non-function

Issue: -

Description

In Bash, local can only be used in functions. In other contexts, it's an error.

Example of incorrect code:

local foo=bar
echo "$foo"

Example of correct code:

foo=bar
echo "$foo"

Exceptions

It's possible to source files containing local from a function context but not from any other context. This is not good practice, but in these cases you can ignore this error.

Further Reading