FUNCTIONS

  • Like other languages, functions can be defined in shell scripts.
  • Useful for splitting up scripts into understandable, reusable pieces.
  • Functions can be called like independent scripts.

  • Syntax for creating a function is:
      function NAME { COMMANDS ; }
    or the short form:
      NAME () { COMMANDS ; }

  • Example:
    $ function hi { echo "Hi! $1" ; }
    $ hi
      Hi!
    $ hi There
      Hi! There