Join Scott Simpson for an in-depth discussion in this video Using functions, part of Learning Bash Scripting.
…During your script development, you may find yourself repeating code blocks.…It's a good practice to not repeat yourself if you don't have…to, and it's a whole lot more maintainable to keep things organized.…Bash functions can help out with that.…To declare one, just type the keyword, function, and…the name of your function, followed by curly braces.…Inside the function goes whatever you want to happen when the function's…called, and then to call the function, just call it by name.…I'll save that and go out to the command line to run it.…And there's hi there, echoed by calling the function greet.…And of course the contents of these functions can be as complex as you like.…
But there's on more thing that functions are great for, wrapping…up code that will process some value that you give the function.…To do that you pass one or more arguments to the function.…That's accomplished by putting values right after the function call.…And up here in the function I'll make a little bit of a change.…Need to accommodate a name and I'll use the variable…
- What is Bash?
- Managing output with grep, awk, and cut
- Understanding Bash script syntax
- Creating a basic Bash script
- Displaying text with "echo"
- Working with numbers, strings, and arrays
- Reading and writing text files
- Working with loops
- Using functions
- Getting user input during execution
- Ensuring a response
Skill Level Beginner
1. Working with the Command Line
2. Building Bash Scripts
3. Control Structures
4. Interacting with the User
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.