ScriptingLesson 51Free preview
Bash Functions
This lesson is part of Bash · All levels
Summary
The Bash function groups commands so they can be used repeatedly with the same name. You define it with a curly braces block, then call it a regular command. The function receives the argument via $1, $2 and returns the value via return or stdout.
Key points
- {...;} defines the function
- Arguments given when calling, read through $1 and $2
- Returns the output status in numerical form
- Local limits the variable to only live in the function
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.