Functions can be defined and used in scripts, and it can be a good idea to do so. One common use is a die function that catches error conditions, prints any given messages, and then exits the script:
die() { printf >&2 '%s\n' "$@" exit 1 } tempfile=$(mktemp) || die 'Could not create temporary file' (( $# > 0 )) || die 'Need at least one argument' [[ $1 != *:* ]] || die 'Colon not allowed in directory name'
Note that you have to declare the functions before you call them. It's best to put the functions near the top of the script.