https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=296050
Bug ID: 296050
Summary: sh.1: Description of 'local' is not very clear
Product: Documentation
Version: Latest
Hardware: Any
OS: Any
Status: New
Severity: Affects Only Me
Priority: ---
Component: Manual Pages
Assignee: [email protected]
Reporter: [email protected]
CC: [email protected]
The sh(1) man page says:
"Variables may be declared to be local to a function by using the local
command. This should appear as the first statement of a function, and the
syntax is: ..."
The part that I personally feel confused about is: "This should appear as the
first statement of a function" - it seems that in practice this is not the
case. I created a test shell script to check this out:
-----------------------------------------------------
#!/bin/sh
a="Val 1"
foo()
{
a="Val 3"
echo "foo(): a before: ${a}"
local a="Val 2"
echo "foo(): a after: ${a}"
}
echo "a before: ${a}"
foo
echo "a after: ${a}"
-----------------------------------------------------
Here I intentionally made 'local' line not the first function statement, but
from the output of the script I can draw that the 'local' keyword still works
as it should, i.e. keeps a variable local to the function. Output of the
script follows:
-----------------------------------------------------
a before: Val 1
foo(): a before: Val 3
foo(): a after: Val 2
a after: Val 3
-----------------------------------------------------
Please, let me know whether it is a bug in the manual page (the implementation
behaviour is correct, but the documentation is not), or it is a bug in the
implementation (the 'local' shouldn't work if it's not a first function
statement), or it is me who interpreted things the wrong way.
--
You are receiving this mail because:
You are on the CC list for the bug.