local variable

A variable that exists only inside one function call and cannot be seen or changed from outside it.

In more detail

Local variables disappear when the call ends, and two functions can use the same local name without interfering. Languages differ in how a variable becomes local: in Python any name assigned inside a function is local, while in Bash you must declare it with the local keyword. Without local, a Bash function writes to the script's global variables.

Example

work() { local result="success"; echo "$result"; }

Related terms

Taught in

References

Certification courses