A function definition is an executable statement; when executed it in-
stalls a function named name and returns an exit status of zero. The
command is normally a list enclosed between ``{'' and ``}''.
Variables may be declared to be local to a function by using a local com-
mand. This should appear as the first statement of a function, and the
syntax is
local [ variable | - ] ...
Local is implemented as a builtin command.
When a variable is made local, it inherits the initial value and exported
and readonly flags from the variable with the same name in the surround-
ing scope, if there is one. Otherwise, the variable is initially unset.
The shell uses dynamic scoping, so that if you make the variable x local
to function f, which then calls function g, references to the variable x
made inside g will refer to the variable x declared inside f, not to the
global variable named x.
The only special parameter than can be made local is ``-''. Making ``-''
local any shell options that are changed via the set command inside the
function to be restored to their original values when the function re-
turns.
The syntax of the return command is
return [ exitstatus ]
It terminates the currently executing function. Return is implemented as
a builtin command.
[^] # Re: man sh
Posté par totof2000 . En réponse au message fonction en bourne shell. Évalué à 3.
http://www.rt.com/man/sh.1.html(...)
Functions
The syntax of a function definition is
name ( ) command
A function definition is an executable statement; when executed it in-
stalls a function named name and returns an exit status of zero. The
command is normally a list enclosed between ``{'' and ``}''.
Variables may be declared to be local to a function by using a local com-
mand. This should appear as the first statement of a function, and the
syntax is
local [ variable | - ] ...
Local is implemented as a builtin command.
When a variable is made local, it inherits the initial value and exported
and readonly flags from the variable with the same name in the surround-
ing scope, if there is one. Otherwise, the variable is initially unset.
The shell uses dynamic scoping, so that if you make the variable x local
to function f, which then calls function g, references to the variable x
made inside g will refer to the variable x declared inside f, not to the
global variable named x.
The only special parameter than can be made local is ``-''. Making ``-''
local any shell options that are changed via the set command inside the
function to be restored to their original values when the function re-
turns.
The syntax of the return command is
return [ exitstatus ]
It terminates the currently executing function. Return is implemented as
a builtin command.