Revision [1352]

This is an old revision of SyntaxFunction made by DavidLee on 2010-05-02 09:12:13.

 

Functions


Functions can be declared in two forms, with or without the keyword "function". These are the equivalent to the forms for ksh.
In both forms the arguments to the functions are passed as positional parameters ($1 .. $N)



name () { list; }


This declares a function "name". The body of the function when executed runs in the same context as the parent shell, with the exception of Positional Parameters ($1 ... $N).
This means that variables assigned within the function have a "side effect" of writing into the global environment for the current shell.

Example

setit () 
{
	 A=$1 ;
}

A="no value"
echo $A
setit value
echo $A


Result
value


function name () { list; }


This declares a function "name". The body of the function when executed runs in the a child shell context. Arguments are passed as positional parameters ($1 .. $N)
This means that variables assigned within the function *do not* have a "side effect" of writing into the global environment for the current shell.

Example

function setit () 
{
	 A=$1 ;
}

A="no value"
echo $A
setit value
echo $A


Result
no value




CoreSyntax
Commands





There are no comments on this page.
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki