Unix Shell Script Creating Functions

June 15, 2007 by Mark Marucot 

Functions are named code blocks that can be referenced and executed as a unit. Functions have an option to take variable number of arguments and may return a value. If function returns a value, calling the function is usually part of an expression.

Syntax

CODE:
  1. name() {
  2. statements
  3. }

Example

CODE:
  1. #!/bin/sh
  2. sum() (
  3. echo $(($A + $B))
  4. )
  5. A=2
  6. B=5
  7. sum $A $B

Related Posts

Comments

Feel free to leave a comment...
and oh, if you want a pic to show with your comment, go get a gravatar!