Skip to content

Latest commit

 

History

History
39 lines (32 loc) · 403 Bytes

functions.md

File metadata and controls

39 lines (32 loc) · 403 Bytes

Defining functions

myfunc() {
    echo "hello $1"
}

Same as above (alternate syntax)

function myfunc {
    echo "hello $1"
}

myfunc "John"

Returning values

myfunc() {
    local myresult='some value'
    echo "$myresult"
}

result=$(myfunc)

Raising errors

myfunc() {
  return 1
}

if myfunc; then
  echo "success"
else
  echo "failure"
fi