Menu

SyntaxFunction

Brad Lanam

Wiki Home
Syntax

Syntax: function and Function Calls

Defining a Function
function <function-name> { <statements> }
function <function-name> ( <parameter-list> ) { <statements> }

The function statement associates an optional parameter‑list and a set of statements with function‑name.

The parameter‑list specifies one or more variable names. These variables are local to the function's statement block.

Function Examples
function helloworld {
  print 'hello world';
}

function hello (arg) {
  # remember to use double quotes
  print "hello ${arg}";
}

function print2 (a b) {
  print "${a} ${b}";
}
Calling a Function

A function with no arguments is simply called by using the function name.

helloworld;

A function call with arguments is passed the arguments as separate values.

hello 'to you';
set a 'to them';
hello ${a};

print2 'hello' 'world';

Wiki Home
Syntax


Related

Wiki: Home
Wiki: Syntax