# Functions

Functions: Functions: Naming a Job, Local Variables and Getting a Value Back, One Script, Several Files: source.

Updated: November 10, 2026

1. [Functions: Naming a Job](https://www.ask-codey.com/lessons/bash-functions) (Journeyman): A function keeps a few commands under one name, so a script says the job's name instead of repeating its lines: define it with name() { }, call it by its name like any command, and hand it arguments, which it reads as $1, $# and "$@".
2. [Local Variables and Getting a Value Back](https://www.ask-codey.com/lessons/bash-function-return-values) (Journeyman): local keeps a function's variables to itself, so it can't change the script's by accident; a function hands back a result by printing it with echo, which the caller catches with $( ), and answers yes or no with return, which if can test.
3. [One Script, Several Files: source](https://www.ask-codey.com/lessons/bash-script-libraries) (Journeyman): A library is a file of functions that several scripts share: each script loads it with source, and finds it from any folder with here=$(dirname "${BASH_SOURCE\[0\]}"), the folder the script itself is saved in.

Source: https://www.ask-codey.com/courses/bash-in-depth/topics/bash-functions
