From the course: Learning Bash Scripting
Unlock this course with a free trial
Join today to access over 24,800 courses taught by industry experts.
Using functions - Bash Tutorial
From the course: Learning Bash Scripting
Using functions
- [Scott] During your script development, you may find yourself repeating the same set of commands, or writing very similar commands while changing just one or two parameters. It's a good practice to not repeat yourself if you don't have to. And keeping scripts organized without duplication makes them a lot more maintainable too. To help organize code, we can use functions, which let us write a set of commands once and then refer to that code by name whenever we need to run it. To create a function, we'll give the function a name, in this case the name fname, and follow that with open and close parentheses. And then we'll add a set of braces to enclose commands that will make up the function. In older scripts, you might see functions defined with a function keyword, and those definitions may or may not have the parenthesis after the function name. Functions need to be declared before they're used. And in many cases you'll…
Contents
-
-
-
-
-
Conditional statements with the "if" keyword4m 17s
-
(Locked)
Working with "while" and "until" loops3m 57s
-
(Locked)
Introducing "for" loops4m 22s
-
(Locked)
Selecting behavior using "case"2m 11s
-
(Locked)
Using functions6m 17s
-
(Locked)
Reading and writing text files3m 25s
-
(Locked)
Challenge: Build a script using control structures33s
-
(Locked)
Solution: Build a script using control structures1m 18s
-
-
-
-