Shell: Functions

(Last Updated On: )

In this tutorial I will show you how to work with functions.

Define Function

You return 0 for success and 1 for failure

  1. function test()
  2. {
  3. return 0
  4. }

Call function with no arguments

  1. test

Call function with arguments

  1. val1='test'
  2. val2='test2'
  3. test $val1 $val2

Call function with arguments that have spaces in the value

  1. val1='test'
  2. val2='test2 test23'
  3. test "${val1}" "${val2}"