June 2025
Beginner to intermediate
473 pages
13h 30m
English
The function keyword defines a function that can be called in the script like a command. The code of the function must be enclosed in curly brackets. Functions must be declared before they are called for the first time and are therefore often placed at the beginning of the script.
Parameters can be passed to functions. Unlike many programming languages, the parameters are not enclosed in parentheses. Within the function, the parameters can be taken from the $1, $2, etc. variables. A function processes parameters in the same way that the script processes command-line arguments. The following mini-script outputs Hello World, Bash!
#!/bin/bashfunction myfunc { echo "Hello World, $1!"}myfunc "Bash" The function keyword is optional. ...
Read now
Unlock full access