Bash Beginner Series #9: Using Functions in Bash

When your bash scripts get bigger and bigger things can get very messy .

You may find yourself rewriting the same pieces of code again and again in different parts of your bash scripts. .

Luckily you can avoid rewriting code by using functions in bash which will make your scripts more organized and readable. .

In this tutorial you will learn to create functions return function values and pass function arguments in bash shell scripts. .

Furthermore you will learn how variables scope work and how to define recursive functions.

There are two different syntaxes for declaring bash functions. The following syntax is the most common used way of creating bash functions.

The second less commonly used of creating bash functions starts with the reserved work function followed by the function name as follows.

Now there are a couple of things you should be well aware of when working with functions.


Read Full Post

News Link:
RSS Link:

Linux Chatter is a news aggregator service that curates some of the best Linux, Cloud, Technical Guides, Hardware and Security news. We display just enough content from the original post to spark your interest. If you like the topic, then click on the 'read full post' button to visit the author's website. Use Linux Chatter to find content from amazing authors!

Note: The content provided has been modified and is not displayed as intended by the author. Any trademarks, copyrights and rights remain with the source.

Disclaimer: Linux Chatter sources content from RSS feeds and personal content submissions. The views and opinions expressed in these articles are those of the authors and do not necessarily reflect those of Linux Chatter.